下面代码获取jdbc ResultSet的数据。
Statement st = dbConn.createStatement();
ResultSet rs = st.executeQuery(
“select * from employee” );
//下面遍历rs
ResultSetMetaData lineInfo = rs.getMetaData();
int columnCount = lineInfo.getColumnCount();
while(rs.next()){
for(int i=1; i<=columnCount; i++){
String columeName = lineInfo.getColumnLabel(i);
String columeType = lineInfo.getColumnTypeName(i);
String columeValue =rs.getString(i);
System.out.println(columeName+" "+columeType+" "+columeValue);
}
}
执行结果:
E_ID NUMBER 1
E_NO NUMBER 10001
E_NAME VARCHAR2 小章
E_SAL NUMBER 2000