Java统计数据库表中记录数

来源:互联网 发布:麦克毕比生涯数据 编辑:程序博客网 时间:2024/06/05 16:51

 

  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; 

 

0 0
原创粉丝点击