private List<Map<String, String>> fun_1() { List<Map<String, String>> rtnList=null; Connection con = null; Statement statement = null; try { con = DBHelper.getConnection(); statement = con.createStatement(); String sqlStr="select ...;"; ResultSet rs = statement.executeQuery(sqlStr);//----executeQuery rtnList=new ArrayList<Map<String,String>>(); if(null!=rs){ rs.last();//让结果集指针指向最后一行数据 logger.info("总数size="+rs.getRow()); rs.beforeFirst();//让结果集指针指回到开始位置,这样才能通过while获取rs中的数据 while (rs.next()) { String customerId = rs.getString("id"); String appId = rs.getString("a_id"); } } }catch (Exception e){ logger.error("异常" + e); }finally{ DBHelper.closeAll(con, statement, null); } return rtnList; } public int fun_2(String a, String b){ Integer count =0; Connection con=null; PreparedStatement ps=null; ResultSet rs =null; try{ con=DBHelper.getConnection(); ps=con.prepareStatement(sqlStr); ps.setString(1, a); ps.setString(2, b); rs=ps.executeQuery();//----executeQuery if(rs.next()){ count =rs.getInt("aCount"); } }catch(SQLException e){ logger.error("失败:"+e.getMessage()); e.printStackTrace(); }catch(Exception e){ logger.error("失败:"+e.getMessage()); e.printStackTrace(); }finally{ DBHelper.closeAll(con, ps, rs); } return count; }
ResultSet统计结果集数量
http://paladin1988.iteye.com/blog/1842734
http://blog.csdn.net/u014726937/article/details/51741617
http://www.cnblogs.com/northeastTycoon/p/5736273.html