1

该程序必须从 MySQL 数据库下载数据。并填写JList. 我想绑定这些数据。

在这里你有一个代码:

 Connection connection = null;
    String dbtime;
    String query = "Select * FROM EMP";
    String[] celDatas = null;
    String[] celNames = null;
    try {

        (...)

        Statement stmt = connection.createStatement();
        ResultSet rs = stmt.executeQuery(query);
        ResultSetMetaData rsmd = rs.getMetaData();

        int NumOfCol = rsmd.getColumnCount();
        celNames = new String[NumOfCol];
        celDatas = new String[NumOfCol];

        for(int weq=1; weq<=NumOfCol; weq++) {
            System.out.println(rsmd.getColumnName(weq));
            celNames[weq-1] = rsmd.getColumnName(weq);
            while (rs.next()) {
                dbtime = rs.getString(weq);
                System.out.println(dbtime);
                celDatas[weq-1] = dbtime;
            }
            rs = stmt.executeQuery(query);
            System.out.println();
        }
    } catch (ClassNotFoundException e) {

    } catch (SQLException e) {

    }


final JList source = new JList(celDatas,celNames);
JScrollPane pane = new JScrollPane(source);
pane.setSize(f.getSize().width-60,300);
pane.setLocation(30,20);

我有问题

final JList source = new JList(celDatas,celNames);

它在 Netbeans 中显示了这个问题:http: //dl.dropbox.com/u/8455739/Java-Problem.png

4

1 回答 1

3
//String[] celDatas = null;
String[][] celDatas = null;
String[] celNames = null;
...
//final JList source = new JList(celDatas,celNames);
final JTable source = new JTable(celDatas,celNames);
于 2012-04-15T11:13:36.333 回答