新分页(oracle&mysql)

String url="jdbc:mysql://127.0.0.1:3306/dongyu";
   conn= DriverManager.getConnection(url,"root","");
   stmt = conn.createStatement();
   rs = stmt.executeQuery("select * from t_statistics order by id");
   rs.last();
  
   int totalcount = rs.getRow();
   int currentPage = 2;
   int resultNum = 5;
   int startIndex = (currentPage-1)*resultNum;
   rs = stmt.executeQuery("select * from t_statistics limit "+startIndex+","+resultNum+"");
   //rs = stmt.executeQuery("select * from t_viscera_picture where id=(select max(id) from t_viscera_picture) for update");
  
   System.out.println("共"+totalcount+"条");
   while(rs.next()) {
   
    System.out.println(rs.getString("id"));
   }

你可能感兴趣的:(oracle,mysql,jdbc)