Statement selectStatement = connection.createStatement();
ResultSet selectResultSet = selectStatement.executeQuery(query);
logger.info("sql query " + selectStatement.toString());
ResultSetMetaData rsmd = selectResultSet.getMetaData();
int columnsNumber = rsmd.getColumnCount();
String[] row = new String[columnsNumber];
int ctr = 0;
logger.info("Reading from database...");
while(selectResultSet.next())
{
for(int i=0;i<columnsNumber;i++){
row[i] = selectResultSet.getString(i+1);
}
System.out.println();
dataFromQuery.put(ctr++, row);
}
selectResultSet.close();
从 HashMap 回读时,它只打印最后一行“n”次。