请看看下面的代码片段:
ResultSetMetaData rsmd = rs.getMetaData();
HashMap<String,Object> map;
while(rs.next()){
int numColumns = rsmd.getColumnCount();
map = new HashMap<String,Object>();
for (int i=1; i<=numColumns; i++) {
String colName = rsmd.getColumnName(i);
if(rsmd.getColumnType(i)==java.sql.Types.ARRAY){
map.put(colName, rs.getArray(colName));
}
else if(rsmd.getColumnType(i)==java.sql.Types.BIGINT){
map.put(colName, rs.getInt(colName));
}
else if(rsmd.getColumnType(i)==java.sql.Types.BOOLEAN){
map.put(colName, rs.getBoolean(colName));
}
else if(rsmd.getColumnType(i)==java.sql.Types.BLOB){
map.put(colName, rs.getBlob(colName));
}
else if(rsmd.getColumnType(i)==java.sql.Types.DOUBLE){
map.put(colName, rs.getDouble(colName));
}
else if(rsmd.getColumnType(i)==java.sql.Types.FLOAT){
map.put(colName, rs.getFloat(colName));
}
else if(rsmd.getColumnType(i)==java.sql.Types.INTEGER){
map.put(colName, rs.getInt(colName));
}
else if(rsmd.getColumnType(i)==java.sql.Types.NVARCHAR){
map.put(colName, rs.getNString(colName));
}
else if(rsmd.getColumnType(i)==java.sql.Types.VARCHAR){
map.put(colName, rs.getString(colName));
}
else if(rsmd.getColumnType(i)==java.sql.Types.TINYINT){
map.put(colName, rs.getInt(colName));
}
else if(rsmd.getColumnType(i)==java.sql.Types.SMALLINT){
map.put(colName, rs.getInt(colName));
}
else if(rsmd.getColumnType(i)==java.sql.Types.DATE){
map.put(colName, rs.getDate(colName));
}
else if(rsmd.getColumnType(i)==java.sql.Types.TIMESTAMP){
map.put(colName, rs.getTimestamp(colName));
}
else{
map.put(colName, rs.getObject(colName));
}
}
//do something with the map here..
}
这正是'toCollection()'已经做的事。不清楚你在问什么。 – EJP
我想看看使用toCollection()方法将CachedRowSet转换为集合的示例。不是用于单列,而是用于整行,即该行的所有列。因此,输出是行的集合,其中每行包含所有列。 –
就是这样。阅读Javadoc。如果您要求提供离线资源,那么您在这里是脱离主题的,但是肯定在Oracle JDBC Tutorial中有一个例子吗?当然你已经尝试了一些你自己的尝试,我们可以评论一下? – EJP