java 类似datatable_java jdbc 得到像C#里的datatable一样的表格
https://blog.csdn.net/weixin_34079140/article/details/114602857
public ArrayList> getDataTale2(String sql) throws SQLException {
ArrayList> dt=new ArrayList>();
sta =(SQLServerPreparedStatement)con.prepareStatement(sql);
rs=(SQLServerResultSet)sta.executeQuery();
SQLServerPreparedStatement stmt = (SQLServerPreparedStatement)con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY );
ResultSet rset = stmt.executeQuery();
ResultSetMetaData rsmd = rset.getMetaData() ;
int columnCount = rsmd.getColumnCount();
ArrayList listNames=new ArrayList<>();
for (int c=0;c
String cName=rsmd.getColumnName(c+1);
listNames.add(cName);
}
dt.add(listNames);
while(rs.next()){
ArrayList list=new ArrayList<>();
for (int c=0;c
String cName=rsmd.getColumnName(c+1);
list.add(rs.getString(cName));
}
dt.add(list);
}
rset.close();
if (rs != null) {
rs.close();
rs = null;
}
if (sta != null) {
sta.close();
sta = null;
}
if (con != null) {
con.close();
con = null;
}
return dt;
}
标签:jdbc,java,sta,rs,ArrayList,null,datatable From: https://www.cnblogs.com/sunny3158/p/17248680.html