//传入你的ResultSet
public static void printRS(ResultSet rs) throws SQLException
{
//检索此 ResultSet 对象的列的编号、类型和属性。
ResultSetMetaData rsmd = rs.getMetaData();
//得到当前的列数
int colCount = rsmd.getColumnCount();
while(rs.next()) { //while控制行数
for(int i = 1; i <= colCount; i ) {//for循环控制列数
if(i > 1) {
System.out.print(",");
}
//得到当前列的列名
String name = rsmd.getColumnName(i);
//得到当前列的值
String value = rs.getString(i);
System.out.print(name "=" value);
} System.out.println();
}
}
对一个未知列数的表查询时,从ResultSet中获取列个数
最新推荐文章于 2022-05-05 17:38:25 发布