我想我已经变成了代码盲了。
我目前正在和朋友一起做一个小项目,我们正在使用JDBC从mySQL数据库中进行选择。
我想要的是,在运行select语句之后,我会得到一些所有数据的“2D”列表。
我想我想要这样的东西-- array[columnName][all of the data inside the selected column]
伪码
// Count all rows from a column
// Count the columns selected
// Adds the column names to 'array'
for(int i = 1; i <= columnCount; i++)
columns.add(resultSetMeta.getColumnName(i));
// Adds the results of the first column to the 'array'
// How can I add the results from n columns?
for(int i = 1; i <= rowCount; i++ ) {
while (resultSet.next())
rows.add(resultSet.getString(i));
}
columnsAndRows.put(columns, rows);ResultSet 变成2D数据类型的最佳方法是什么?ResultSet**,时,如何移动到下一列?**发布于 2014-04-21 13:00:05
您可以对键值对使用hashmap,其中将结果集元数据和值作为结果集值作为键。
HashMap<String, Object> p = new HashMap<String, Object>();
p.put("ResultSetkey1","ResultSetvalue1");
p.put("ResultSetkey2","ResultSetvalue2");另外,我想说使用ResultsetUtils ResultsetUtils
https://stackoverflow.com/questions/23197923
复制相似问题