Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- i want combobox to display 3 different kind of names i.e name,city and gotra
- String searchby= cbsearch.getSelectedItem().toString();
- if(searchby.equals(""))
- JOptionPane.showMessageDialog(null," SELECT ANY ONE EITHER NAME,GOTRA,CITY");
- if(cbsearch.getSelectedItem().toString().equals("Name"))
- {
- try //1st combobox is cbsearch
- { //2nd combobox is cbdisplay
- cbdisplay.setEditable(true);
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- Connection con=DriverManager.getConnection("jdbc:odbc:wanisamajDB");
- String query="Select Name from FAMILYcensus;";
- Statement st=con.createStatement();
- ResultSet res=st.executeQuery(query);
- String temp;
- while(res.next())
- {
- temp=res.getString(1);
- cbdisplay.addItem(temp);
- }
- con.close();
- st.close();
- }
- catch(Exception e)
- {
- System.out.println("Error");
- }
- finally
- {
- //P1.add(cmb);
- //cbregno.setBounds(175,30,150,20);
- cbdisplay.setSize(150,20);
- }
- }
- if(cbsearch.getSelectedItem().toString().equals("City"))
- {
- try
- {
- cbdisplay.setEditable(true);
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- Connection con=DriverManager.getConnection("jdbc:odbc:wanisamajDB");
- String query="Select LivingArea from FAMILYcensus;";
- Statement st=con.createStatement();
- ResultSet res=st.executeQuery(query);
- String temp;
- while(res.next())
- {
- temp=res.getString(1);
- cbdisplay.addItem(temp);
- }
- con.close();
- st.close();
- }
- catch(Exception e)
- {
- System.out.println("Error");
- }
- finally
- {
- //P1.add(cmb);
- //cbregno.setBounds(175,30,150,20);
- cbdisplay.setSize(150,20);
- }
- }
- if(cbsearch.getSelectedItem().toString().equals("Gotra"))
- {
- try
- {
- cbdisplay.setEditable(true);
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- Connection con=DriverManager.getConnection("jdbc:odbc:wanisamajDB");
- String query="Select Gotra from FAMILYcensus;";
- Statement st=con.createStatement();
- ResultSet res=st.executeQuery(query);
- String temp;
- while(res.next())
- {
- temp=res.getString(1);
- cbdisplay.addItem(temp);
- }
- con.close();
- st.close();
- }
- catch(Exception e)
- {
- System.out.println("Error");
- }
- finally
- {
- //P1.add(cmb);
- //cbregno.setBounds(175,30,150,20);
- cbdisplay.setSize(150,20);
- }
- cbsearch.addActionListener (new ActionListener () {
- public void actionPerformed(ActionEvent e) {
- //change the values in the second combo box
- }
- });
Add Comment
Please, Sign In to add comment