Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners combo box connection
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sanjay nag.k
combo box connection
1 Answer(s)      2 years and 10 months ago
Posted in : Java Beginners


how to provide connection between three combo boxes,if my 1st combo box is course and 2nd combo box is semester and 3rd combo box is my subjects.what's the coding to provide the connection between this three combo boxes.


Advertisement
View Answers

February 1, 2012 at 5:22 PM


Here is Java swing code:

import java.sql.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class DynamicCombobox {

public static void main(final String args[])throws Exception {
JFrame frame = new JFrame();
frame.setLayout(null);
JLabel lab1=new JLabel("Course");
        final JComboBox combo1=new JComboBox();
        combo1.addItem("--Select--");
        Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           final Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from course");

           while(rs.next()){
           combo1.addItem(rs.getString("courseName"));
           }
           JLabel lab2=new JLabel("Semester");
           final JComboBox combo2=new JComboBox();
           JLabel lab3=new JLabel("Subjects");
           final JComboBox combo3=new JComboBox();

    combo1.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
        try{
    ItemSelectable is = (ItemSelectable)e.getSource();
    String str=selectedString(is);
    ResultSet rs1 = st.executeQuery("Select semester from course c,semester s where c.courseName='"+str+"' and c.courseid=s.courseid"); 
    while(rs1.next()){
        combo2.addItem(Integer.toString(rs1.getInt("semester")));
    }
    combo2.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e1) {
    ItemSelectable isb = (ItemSelectable)e1.getSource();
    int sem=Integer.parseInt(selectedString(isb));
    try{
    ResultSet rs2 = st.executeQuery("Select subjects from semester s,subjects sub where s.semester="+sem+" and s.semesterid=sub.semesterid"); 
    while(rs2.next()){
        combo3.addItem(rs2.getString("subjects"));
    }
    }
    catch(Exception exception){}

    }
    });
        }
        catch(Exception ex){}
    }
    });
    lab1.setBounds(10,10,100,20);
    combo1.setBounds(120,10,100,20);

    lab2.setBounds(10,40,100,20);
    combo2.setBounds(120,40,100,20);

    lab3.setBounds(10,70,100,20);
    combo3.setBounds(120,70,100,20);

    frame.add(lab1);
    frame.add(combo1);

    frame.add(lab2);
    frame.add(combo2);

    frame.add(lab3);
    frame.add(combo3);

    frame.pack();
    frame.setVisible(true);
    }
    static private String selectedString(ItemSelectable is) {
    Object selected[] = is.getSelectedObjects();
    return ((selected.length == 0) ? "null" : (String)selected[0]);
    }
}

If you want the code is JSP, then go through the following link:

http://www.roseindia.net/answers/viewqa/Ajax/15250-DropDown-in-ajax+jsp.html



Related Tutorials/Questions & Answers:
combo box connection
combo box connection  how to provide connection between three combo boxes,if my 1st combo box is course and 2nd combo box is semester and 3rd combo box is my subjects.what's the coding to provide the connection between this three
combo box
combo box  Hi, [_|] dropdown box [ ] [INCLUDE... a screen like this using jsp-servlet(or DAO,DTO),in that drop down box i should get
Advertisements
populate Combo Box dynamically
populate Combo Box dynamically  Hi, How to populate the Combo Box dynamically using Flex with Jsp's
combo box - JSP-Servlet
combo box  how to get a combo box in jsp page which allows editing as well as list box
assigning arraylist to combo box
assigning arraylist to combo box  Hi I am busy coding the Airline Reservation program, i have an arraylist of locations which i want to assing to the combo box. please help
date in combo box
date in combo box  strong texthello, how can i desplay the current year and next year in combo box???!!! it must be uppdate atumaticaly every year>>>
populating the combo box - Struts
populating the combo box  Hi I am having problem populating the combo box with a table in MS SQL Server 2005 Management Studio Express. Belo... with the database table. What is the connection string that i am suppose to write
combo box value
combo box value   i want to populate one combo box value based on another combo box value using ajax   1)country.jsp: <%@page...("com.mysql.jdbc.Driver").newInstance(); Connection con = DriverManager.getConnection("jdbc
combo box value
combo box value   i want to populate one combo box value based on another combo box value using ajax   1)country.jsp: <%@page import...(); Connection con = DriverManager.getConnection("jdbc:mysql://localhost
Combo Box - Struts
Combo Box  I hava acombo box cnnected to my database via html collections. When selecting an option, i want to display specific parts (sectons) on my web page....am trying to use logic:present and logic:empty but its not working
Helps with combo box and frame
Helps with combo box and frame  Hi i have a combobox and when i click... on the second window and click confirm i would have the information on the combo box. i... combo; JTextField txtBox; private String PersonViewing; private String
java combo box
java combo box  how to display messagedialogbox when the combobox is null, Thanks in advance
Problem With Combo Box Editable Property
Problem With Combo Box Editable Property  Hi I am new To Flex i had set Combo Box Editable Property as true. But I didn't get the property filtering in the combo box like when you enter text "S" in the combo box then the names
combo box code problem
combo box code problem  in this my problem related to : when i select state MP then i wil open the its corresponding city but in database it only...;% Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con
Loading combo box from oracle
Loading combo box from oracle  how can i load values into a combobox from oracle database when a value is selected in another combo box
combo box - JSP-Servlet
combo box  I am using a JSP form in which a combobox is given and I want to populate data in it from database and on the basis of yhe selected item I want to display related data in a textbox  Hi Friend, Create
Dojo Combo Box
Dojo Combo Box          In this section, you will learn what is combo box and how to create a combo box in dojo. For creating the Combo box  you need "
JavaScript Dynamic Combo Box
JavaScript Dynamic Combo Box Here we are going to create dynamic combo box. For this, we have created two combo boxes where combo1 represents countries... in respective arrays. As the user selects a country from the first combo box, the cities
Combo box value Error - WebSevices
Combo box value Error   if($_SERVER['REQUEST_METHOD'] == 'POST' ) { $visa =trim($_POST['hdVisa']); } document.frmProposal.hdVisa.value = document.getElementById('cmbVisa').value; Error
how to create a combo box in html
how to create a combo box in html  <tr> <td>Number<span class=mandatory>*</span></td> <td> <select name="number" id="course" style="width:158px;"> <option value="none">----Select
How to create Combo Box in SWT
How to create Combo Box in SWT       This section illustrates you how to create a combo box... an action on the second combo box. The items tea , coffee and cold drink
Retrieving Data from Database to fill Combo Box
Page with a combo box and a label. I have a database that has two fields id and an image. Now I want to fill the combo box with image and on selecting a particular image in combo box it should be displayed on the label. My combo box is only
how to get selected name from combo box
how to get selected name from combo box   i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz
how to get selected name from combo box
how to get selected name from combo box   i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz
Combo Box operation in Java Swing
Combo Box operation in Java Swing   ... the Combo Box component, you will learn how to add items to the combo box, remove items from the combo box. This program shows a text field, a combo box
how to get selected name from combo box
how to get selected name from combo box  i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz answer
how to get selected name from combo box
how to get selected name from combo box  i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz answer
how to get selected name from combo box
how to get selected name from combo box  i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz answer
loading value into combo box by selecting value from other combo box - JSP-Servlet
loading value into combo box by selecting value from other combo box  ... is that as i select state from state_combo_box,then the next combo box is dynamically... box with constituency corresponding to district..... all three combo box
Populate a combo box using data from a database
Populate a combo box using data from a database  Hi Guys, In need... combo box which will then load the next combo box values, now i know how... to the client using ajax, and then populate the combo box, I must'nt reload
how to get combo box value - JSP-Servlet
how to get combo box value  i have created 1 servlet & 1 jsp page. in servlet page i have fired query & fetched name & its id & that i have shown in combo box in jsp page: (small part of my code) "> now i want
 

 

 

DMCA.com