Java新手,所以这里是:
我想通过这样做来获取我填充的arrayList:
ar.add(rs.getString(y));
这会产生这样的东西:
值1,值2,值3,...
并像这样返回它:
return (Object[][]) ar.toArray();
or
String[][] res = new String[ar.size()][];
return ar.toArray(res);
尽管这似乎只是将Null、Null、Null全部放在其中。
当它通过ar.add(...) 填充时,我确保它确实有数据(并且确实有)。
所有这些都是为了让我可以创建一个表:
TableModel model = new EditableTableModel(columnTitles, dataEntries);
dataEntries是它需要的Object[][] 。
原始的dataEntries 代码是:
Object[][] dataEntries = {
{ "value1", "value2", "value3", "value4", "value5", "value6", "value7" },
{ "value1", "value2", "value3", "value4", "value5", "value6", "value7" },
etc...
};
第一次测试时效果很好。这些值按应有的方式显示在jTable中。
这是我的完整代码:
private void initialize() throws Exception {
[more code here]
Object[][] dataEntries = reloadData();
TableModel model = new EditableTableModel(columnTitles, dataEntries);
table = new JTable(model);
[more code here]
}
@SuppressWarnings("unchecked")
private Object[][] reloadData() throws Exception {
SQLiteJDBCLoader.initialize();
ArrayList<String> ar = new ArrayList<String>();
SQLiteDataSource dataSource = new SQLiteDataSource();
dataSource.setUrl(dbPath);
try {
ResultSet rs = dataSource
.getConnection()
.createStatement()
.executeQuery("Select "
+ "data_script, "
+ "data_status, "
+ "data_errors, "
+ "data_tester, "
+ "data_rundate, "
+ "data_tools, "
+ "ID "
+ "FROM allData");
int row = 5;
int col = 6;
while (rs.next()) {
for (int x = 1; x < row; x++) {
for (int y = 1; y < col; y++) {
ar.add(rs.getString(y));
}
}
}
}
我可能做错了什么?
慕的地10843
慕码人2483693
相关分类