第二次显示ResultSet已用尽我调用此方法。第一次没有错误。在obj[i][j] = rs.getString(1);
public static void createTableModel(ResultSet rs) {
try {
rs.first();
while(rs.next()) {
count++;
}
String [][] obj;
obj = new String [count][3];
rs.first();
for (int i=0; i<count; i++) {
for (int j=0; j < 3; j++) {
if(j == 0) {
obj[i][j] = rs.getString(1);
}
else if(j == 1) {
obj[i][j] = Integer.toString(rs.getInt(2));
}
else if(j == 2) {
obj[i][j] = rs.getString(6);
}
}
rs.next();
}
GlobalVariables.table1 = new DefaultTableModel(obj,
new String [] {
"Name", "Age", "License No"
}
);
}
catch (Exception e) {
e.printStackTrace();
}
}
答案 0 :(得分:0)
我将结果集转换为列表&gt;
List<ArrayList<String>> result = new ArrayList<>();
do{
ArrayList<String> row = new ArrayList<>(6);
int i = 1;
while (i <= 6) {
row.add(GlobalVariables.data3.getString(i++));
}
result.add(row);
}while (GlobalVariables.data3.next());
它解决了这个问题。我仍然不知道为什么它显示错误的结果集。