这只返回最后一行数据:
ResultSetMetaData md = rs.getMetaData();
while (rs.next()) {
for (int i = 1; i <= md.getColumnCount(); i++) {
data_map.put(md.getColumnName(i), rs.getString(i));
}
System.out.println(data_map);
con.close();
return data_map;
}
我尝试使用下面的代码,这只返回第一行数据。返回所有数据行我做错了什么?
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery(sql);
rs.last();
int rows=rs.getRow();
System.out.println("Number of rows"+rows);
ResultSetMetaData md=rs.getMetaData();
int cols=md.getColumnCount();
System.out.println("Number of rows"+cols);
String data[][]= new String[rows][cols];
int i=0;
rs.beforeFirst();
while(rs.next()) {
for(int j=0; j<=cols; j++) {
data[i][j]=rs.getString(j+1);
System.out.println(data[i][j]);
}
i++;
}
return data;