数据未显示在数据库的jList方法中

时间:2014-11-27 12:25:49

标签: java database swing jlist

我正在使用以下代码:

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();              
}

0 个答案:

没有答案