Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public autogen() {
- initComponents();
- //JComboBox g1 = new JComboBox();
- try{
- String url ="jdbc:sqlserver://localhost:1433;databaseName=class ";
- String use = "mali";
- String password = "12345";
- Connection con = DriverManager.getConnection(url,use,password);
- Statement st = con.createStatement ();
- ResultSet rs;
- String sq = "SELECT DISTINCT(grd) FROM addteacher";
- rs= st.executeQuery(sq);
- while(rs.next()){
- jComboBox3.addItem("--Select a Grade--");
- jComboBox3.addItem(rs.getString("grd"));
- }
- }
- catch (Exception evt){
- }
- jComboBox3.addItemListener(new ItemListener(){
- public void itemStateChanged(ItemEvent e){
- if (e.getSource() == jComboBox3)
- jComboBox1.removeAllItems();
- {
- if(!(jComboBox3.getSelectedItem() == null )){
- try{
- String url ="jdbc:sqlserver://localhost:1433;databaseName=class ";
- String use = "mali";
- String password = "12345";
- Connection con = DriverManager.getConnection(url,use,password);
- Statement st = con.createStatement ();
- ResultSet rs;
- String p = jComboBox3.getSelectedItem().toString();
- String sq = "SELECT DISTINCT(sub) FROM addteacher WHERE grd= '" + p +"' ";
- rs= st.executeQuery(sq);
- while(rs.next()){
- jComboBox1.addItem("--Select a Subject--");
- jComboBox1.addItem(rs.getString("sub"));
- }
- }
- catch (Exception evt){
- }
- }
- else { }
- } }});
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- JComboBox g1 = new JComboBox();
- setLayout(new FlowLayout());
- add(g1);
- pack();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement