现在的位置: 首页 > 综合 > 正文

Java统计数据库表中记录数

2017年12月19日 ⁄ 综合 ⁄ 共 561字 ⁄ 字号 评论关闭

 

  1. public static int count(String txyl_table) {// 获取用户数量 
  2.     int i = 0;// Store_Information 
  3.     Connection con = DB.getConnnection(); 
  4.     try { 
  5.         Statement stmt = con.createStatement(); 
  6.         ResultSet rset = stmt.executeQuery("select count(*)as totalCount from "+ txyl_table);  
  7.         if(rset.next()) {  
  8.            i=rset .getInt("totalCount");  
  9.         } 
  10.     } catch (Exception e) { 
  11.         System.err.println("你确定你没有输错表明么???"); 
  12.          e.printStackTrace(); 
  13.     } finally { 
  14.         DB.closeConn(con); 
  15.     } 
  16.     System.out.println(i); 
  17.     return i; 

 

抱歉!评论已关闭.