Background: Before you want to convert the records in a database into a list, you need to get the data in the resultset based on the data type you don't use, get it by using the obtain method, and now automatically extract the relevant data based on the data type with the metadata information in resultset Avoids the tedious operation of each type of judgment;
Realize:
private static List<List<Object>> list = new ArrayList<List<Object>>();
public static String queryAll() {
Connection conn = null;
Statement sta = null;
ResultSet rs = null;
try {
PhoenixDB pDB = new PhoenixDB();
conn = pDB.getConn();
sta = conn.createStatement();
rs = sta.executeQuery("select * from tb");
ResultSetMetaData md = rs.getMetaData(); //获得结果集结构信息,元数据
int columnCount = md.getColumnCount(); //获得列数
while (rs.next()) {
List<Object> l = new ArrayList<Object>();
for (int i = 1; i <= columnCount; i++) {
l.add(rs.getObject(i));
}
list.add(l);
}
} catch (SQLException e) {
e.printStackTrace();
}
return "success";
}
To convert a JDBC resultset result set to a list