Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. public autogen() {
  2.  
  3. initComponents();
  4. //JComboBox g1 = new JComboBox();
  5.  
  6. try{
  7. String url ="jdbc:sqlserver://localhost:1433;databaseName=class ";
  8. String use = "mali";
  9. String password = "12345";
  10. Connection con = DriverManager.getConnection(url,use,password);
  11. Statement st = con.createStatement ();
  12. ResultSet rs;
  13.  
  14. String sq = "SELECT DISTINCT(grd) FROM addteacher";
  15. rs= st.executeQuery(sq);
  16. while(rs.next()){
  17. jComboBox3.addItem("--Select a Grade--");
  18. jComboBox3.addItem(rs.getString("grd"));
  19. }
  20.  
  21. }
  22. catch (Exception evt){
  23.  
  24. }
  25. jComboBox3.addItemListener(new ItemListener(){
  26. public void itemStateChanged(ItemEvent e){
  27. if (e.getSource() == jComboBox3)
  28. jComboBox1.removeAllItems();
  29. {
  30. if(!(jComboBox3.getSelectedItem() == null )){
  31.  
  32. try{
  33. String url ="jdbc:sqlserver://localhost:1433;databaseName=class ";
  34. String use = "mali";
  35. String password = "12345";
  36. Connection con = DriverManager.getConnection(url,use,password);
  37. Statement st = con.createStatement ();
  38. ResultSet rs;
  39. String p = jComboBox3.getSelectedItem().toString();
  40. String sq = "SELECT DISTINCT(sub) FROM addteacher WHERE grd= '" + p +"' ";
  41. rs= st.executeQuery(sq);
  42. while(rs.next()){
  43. jComboBox1.addItem("--Select a Subject--");
  44. jComboBox1.addItem(rs.getString("sub"));
  45. }
  46.  
  47. }
  48. catch (Exception evt){
  49.  
  50. }
  51. }
  52. else { }
  53. } }});
  54. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  55.  
  56.  
  57. JComboBox g1 = new JComboBox();
  58. setLayout(new FlowLayout());
  59. add(g1);
  60.  
  61. pack();
  62.  
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement