gpt4 book ai didi

java - JTable 使用数组字符串。这些数据在 try-catch 中

转载 作者:行者123 更新时间:2023-11-29 06:00:51 24 4
gpt4 key购买 nike

程序必须从 MySQL 数据库下载数据。并填写 JList。我想绑定(bind)这个数据。

这里有一个代码:

 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

最佳答案

//String[] celDatas = null;
String[][] celDatas = null;
String[] celNames = null;
...
//final JList source = new JList(celDatas,celNames);
final JTable source = new JTable(celDatas,celNames);

关于java - JTable 使用数组字符串。这些数据在 try-catch 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10161443/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com