Guest User

Untitled

a guest
Sep 3rd, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. i want combobox to display 3 different kind of names i.e name,city and gotra
  2. String searchby= cbsearch.getSelectedItem().toString();
  3. if(searchby.equals(""))
  4. JOptionPane.showMessageDialog(null," SELECT ANY ONE EITHER NAME,GOTRA,CITY");
  5. if(cbsearch.getSelectedItem().toString().equals("Name"))
  6. {
  7. try //1st combobox is cbsearch
  8. { //2nd combobox is cbdisplay
  9.  
  10. cbdisplay.setEditable(true);
  11. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  12. Connection con=DriverManager.getConnection("jdbc:odbc:wanisamajDB");
  13. String query="Select Name from FAMILYcensus;";
  14. Statement st=con.createStatement();
  15. ResultSet res=st.executeQuery(query);
  16. String temp;
  17.  
  18. while(res.next())
  19. {
  20.  
  21. temp=res.getString(1);
  22. cbdisplay.addItem(temp);
  23.  
  24.  
  25. }
  26. con.close();
  27. st.close();
  28.  
  29. }
  30. catch(Exception e)
  31. {
  32. System.out.println("Error");
  33. }
  34. finally
  35. {
  36. //P1.add(cmb);
  37. //cbregno.setBounds(175,30,150,20);
  38. cbdisplay.setSize(150,20);
  39. }
  40. }
  41. if(cbsearch.getSelectedItem().toString().equals("City"))
  42. {
  43. try
  44. {
  45.  
  46. cbdisplay.setEditable(true);
  47. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  48. Connection con=DriverManager.getConnection("jdbc:odbc:wanisamajDB");
  49. String query="Select LivingArea from FAMILYcensus;";
  50. Statement st=con.createStatement();
  51. ResultSet res=st.executeQuery(query);
  52. String temp;
  53.  
  54. while(res.next())
  55. {
  56.  
  57. temp=res.getString(1);
  58. cbdisplay.addItem(temp);
  59.  
  60.  
  61. }
  62. con.close();
  63. st.close();
  64.  
  65. }
  66. catch(Exception e)
  67. {
  68. System.out.println("Error");
  69. }
  70. finally
  71. {
  72. //P1.add(cmb);
  73. //cbregno.setBounds(175,30,150,20);
  74. cbdisplay.setSize(150,20);
  75. }
  76. }
  77. if(cbsearch.getSelectedItem().toString().equals("Gotra"))
  78. {
  79. try
  80. {
  81.  
  82. cbdisplay.setEditable(true);
  83. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  84. Connection con=DriverManager.getConnection("jdbc:odbc:wanisamajDB");
  85. String query="Select Gotra from FAMILYcensus;";
  86. Statement st=con.createStatement();
  87. ResultSet res=st.executeQuery(query);
  88. String temp;
  89.  
  90. while(res.next())
  91. {
  92.  
  93. temp=res.getString(1);
  94. cbdisplay.addItem(temp);
  95.  
  96.  
  97. }
  98. con.close();
  99. st.close();
  100.  
  101. }
  102. catch(Exception e)
  103. {
  104. System.out.println("Error");
  105. }
  106. finally
  107. {
  108. //P1.add(cmb);
  109. //cbregno.setBounds(175,30,150,20);
  110. cbdisplay.setSize(150,20);
  111. }
  112.  
  113. cbsearch.addActionListener (new ActionListener () {
  114. public void actionPerformed(ActionEvent e) {
  115. //change the values in the second combo box
  116.  
  117. }
  118. });
Add Comment
Please, Sign In to add comment