try{
connection = dataSource.getConnection();
callableStatement.setInt(2, clientId);
....... // some stuff
resultSet = callableStatement.executeQuery();
}
现在我有一个resultSet,但不知道列名?我该怎么回头呢?
答案 0 :(得分:2)
试试这个......
ResultSetMetaData rsmd = resultSet.getMetaData();
int columnCount = rsmd.getColumnCount();
// The column count starts from 1
for (int i=1; i<=columnCount; i++ ) {
String name = rsmd.getColumnName(i);
// Do stuff with name
}
答案 1 :(得分:0)
resultSet.getMetadata()
会返回一个包含列名称的ResultSetMetaData
对象(例如resultSet.getMetadata().getColumnName(1)
)
答案 2 :(得分:0)
显示:
ResultSetMetaData rsmd = resultSet.getMetaData();
String name = rsmd.getColumnName(1);
答案 3 :(得分:0)
您可以使用ResultSetMetaData
ResultSetMetaData metadata = resultSet.getMetaData();
int columnCount = metadata.getColumnCount();
ArrayList<String> columns = new ArrayList<String>();
for (int i = 1; i < columnCount; i++) {
String columnName = metadata.getColumnName(i);
columns.add(columnName);
}
答案 4 :(得分:0)
以下代码有助于获取表格的列名。
ResultSetMetaData rsmd = resultSet.getMetaData();
int columnsCount = rsmd.getColumnCount();
int i=1;
while (i <= columnsCount){
String columnName = rsmd.getColumnName(i);
i++;
}