我正在使用以下代码:
DefaultListModel dModel = (DefaultListModel)jList1.getModel();
txtBilln.enableInputMethods(false);
try{
Class.forName("com.mysql.jdbc.Drvier");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/jns","root","jns");
Statement stmt = null ;
ResultSet rs = null ;
String SQL = "SELECT * FROM ELEB";
stmt = con.createStatement();
rs = stmt.executeQuery(SQL);
while (rs.next()){
String bno= rs.getString("billn");
String cnamme = rs.getString("cname");
dModel.addElement(bno + "-" + cnamme);
}
jList1.setModel(dModel);
con.close();
}catch(Exception e){
JOptionPane.showMessageDialog(this, e.getMessage());
e.printStackTrace();
}