日期:2014-05-20 浏览次数:20681 次
class Classify implements ActionListener { public void actionPerformed(ActionEvent e) { try{ String CLASS=String.valueOf(c_or_in_class.getSelectedItem()); Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=数据库课程设计","sa","123"); Statement stmt=con.createStatement(); String SQL="SELECT distinct product_name FROM Product WHERE product_class='"+CLASS+"'"; System.out.println(SQL); ResultSet rs=stmt.executeQuery(SQL); while(rs.next()){ c_or_in_proName.removeAllItems(); //如果有这条语句下拉列表里就只有一个Item c_or_in_proName.addItem(rs.getString(1)); }}catch(Exception ex){} } }
class Classify implements ActionListener { public void actionPerformed(ActionEvent e) { try{ String CLASS=String.valueOf(c_or_in_class.getSelectedItem()); Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=数据库课程设计","sa","123"); Statement stmt=con.createStatement(); String SQL="SELECT distinct product_name FROM Product WHERE product_class='"+CLASS+"'"; System.out.println(SQL); ResultSet rs=stmt.executeQuery(SQL); c_or_in_proName.removeAllItems(); //在循环外面先移除所有选项 while(rs.next()){ c_or_in_proName.addItem(rs.getString(1)); }}catch(Exception ex){} } }