admin 管理员组文章数量: 1184232
2024年1月16日发(作者:十进制十六进制转换公式)
*/public static List executeQuery(Connection con, String sql, Class> c) throws SQLException{PreparedStatement pst = null;ResultSet rs = null;try {pst = eStatement(sql);rs = eQuery();return getListFromRs(rs, c);}finally{closeRs(rs);closePst(pst);}}/*** 得到结果集存储到list中* @param rs 查询的结果集* @return* @throws SQLException*/public static List> getListFromRs(ResultSet rs) throws SQLException{ResultSetMetaData md = aData();//得到结果集列的属性int columns = umnCount();//得到记录有多少列int i;List> list = new ArrayList>();while(()){Map map = new HashMap();for(i = 0; i
(umnName(i + 1), getValueByType(rs, umnType(i + 1), umnName(i + 1)));}(map);}return list;}/**
/**** 关闭数据库多个结果集* @param rss*/public static void rss){for(ResultSet rs: rss){if(rs != null){try {();} catch (SQLException e) {}}}}/*** 关闭数据库多个psts* @param psts*/public static void psts){for(Statement pst: psts){if(pst != null){try {();} catch (SQLException e) {}}}}/*** 关闭数据库所得到的多个链接* @param cons*/public static void cons){for(Connection con: cons){
if(con != null){try {();} catch (SQLException e) {}}}}}
版权声明:本文标题:python数据库输出结果存到列表中_从数据库得到的结果集存放到List集合中 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1705415430a483842.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论