Resultset获取数据 贴个代码:
public List<String> getsutablesColumns(String collectionName) {
List<String> columns = new ArrayList<>();
try {
ResultSet resultSet = stmt.executeQuery("describe "+collectionName);
while(resultSet.next()){
String column = resultSet.getString(1);
columns.add(column);
}
} catch (SQLException e) {
e.printStackTrace();
}
return columns;
}
这里的sql是:describe 表名
所以根据下标获取是最方便的。
如果是查询常规数据:
比如:select * from xxx,那么,则通过字段名称取值:
while(resultSet .next()){
int id = resultSet .getInt("id");
String name = resultSet .getString("name");
String gender = resultSet .getString("gender");
}