Java SELECT FOUND_ROWS()始终返回一个,如何解决此问题
以下sql始终返回一个Java SELECT FOUND_ROWS()始终返回一个,如何解决此问题,java,jsp,servlets,pagination,Java,Jsp,Servlets,Pagination,以下sql始终返回一个SELECT FOUND\u ROWS() 我在net中遵循了以下示例: public List<Employee> viewAllEmployees( int offset, int noOfRecords) { String query = "select SQL_CALC_FOUND_ROWS * from employee limit "
SELECT FOUND\u ROWS()
我在net中遵循了以下示例:
public List<Employee> viewAllEmployees(
int offset,
int noOfRecords)
{
String query = "select SQL_CALC_FOUND_ROWS * from employee limit "
+ offset + ", " + noOfRecords;
List<Employee> list = new ArrayList<Employee>();
Employee employee = null;
try {
connection = getConnection();
stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
employee = new Employee();
employee.setEmployeeId(rs.getInt("emp_id"));
employee.setEmployeeName(rs.getString("emp_name"));
employee.setSalary(rs.getDouble("salary"));
employee.setDeptName(rs.getString("dept_name"));
list.add(employee);
}
rs.close();
rs = stmt.executeQuery("SELECT FOUND_ROWS()");
if(rs.next())
this.noOfRecords = rs.getInt(1);
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}finally
{
try {
if(stmt != null)
stmt.close();
if(connection != null)
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return list;
}
公共列表视图所有员工(
整数偏移,
国际会议(会议记录)
{
String query=“从员工限额中选择SQL\u计算\u找到的\u行”
+偏移量+“,”+noOfRecords;
列表=新的ArrayList();
Employee=null;
试一试{
connection=getConnection();
stmt=connection.createStatement();
ResultSet rs=stmt.executeQuery(查询);
while(rs.next()){
雇员=新雇员();
employee.setEmployeeId(rs.getInt(“emp_id”);
employee.setEmployeeName(rs.getString(“emp_name”);
员工工资(双倍(“工资”);
employee.setDeptName(rs.getString(“部门名称”);
列表。添加(员工);
}
rs.close();
rs=stmt.executeQuery(“选择找到的行()”;
如果(rs.next())
this.noOfRecords=rs.getInt(1);
}捕获(SQLE异常){
e、 printStackTrace();
}catch(classnotfounde异常){
e、 printStackTrace();
}最后
{
试一试{
如果(stmt!=null)
stmt.close();
if(连接!=null)
connection.close();
}捕获(SQLE异常){
e、 printStackTrace();
}
}
退货清单;
}
这是我基于上面的代码:
public List<TempcardViewModel> getTempcardHistory(String query) {
TempcardViewModel tempcardObj = null;
List<TempcardViewModel> tempcardList = new ArrayList<TempcardViewModel>();
Connection connection = getConnection();
if (connection != null) {
try {
PreparedStatement assingedTempcardPS = connection.prepareStatement(query);
ResultSet assingedTempcardlist_rst = assingedTempcardPS.executeQuery();
while (assingedTempcardlist_rst.next()) {
tempcardObj = new TempcardViewModel();
tempcardObj.setEmpid(assingedTempcardlist_rst.getInt("empid"));
tempcardObj.setEmpname( assingedTempcardlist_rst.getString("empname"));
tempcardObj.setTempcardnumber(assingedTempcardlist_rst.getString("tempcardnumber"));
tempcardObj.setIssuedate(assingedTempcardlist_rst.getString("issuedate"));
tempcardObj.setTempcardstatus(assingedTempcardlist_rst.getString("tempcardstatus"));
tempcardList.add(tempcardObj);
}
assingedTempcardPS.close();
assingedTempcardlist_rst.close();
PreparedStatement noOfRecordsPS = connection.prepareStatement("SELECT FOUND_ROWS();");
assingedTempcardlist_rst = noOfRecordsPS.executeQuery();
if(assingedTempcardlist_rst.next())
this.noOfRecords = assingedTempcardlist_rst.getInt(1);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
closeConnection(connection, null, null);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
return tempcardList;
}
公共列表getTempcardHistory(字符串查询){
TempcardViewModel tempcardObj=null;
List tempcardList=新建ArrayList();
Connection=getConnection();
if(连接!=null){
试一试{
PreparedStatement assingedTempcardPS=connection.prepareStatement(查询);
结果set assingedTempcardlist\u rst=assingedTempcardPS.executeQuery();
while(assingedTempcardlist_rst.next()){
tempcardObj=新的TempcardViewModel();
tempcardObj.setEmpid(assignedtempcardlist_rst.getInt(“empid”);
tempcardObj.setEmpname(assingedTempcardlist_rst.getString(“empname”);
tempcardObj.setTempcardnumber(assignedtempcardlist_rst.getString(“tempcardnumber”);
tempcardObj.setIssuedate(assignedtempcardlist_rst.getString(“issuedate”);
tempcardObj.setTempcardstatus(assingedTempcardlist_rst.getString(“tempcardstatus”);
tempcardList.add(tempcardObj);
}
assignedtempcardps.close();
AssignedTempCardList_rst.close();
PreparedStatement noOfRecordsPS=connection.prepareStatement(“选择已找到的行();”);
assingedTempcardlist\u rst=noOfRecordsPS.executeQuery();
if(assingedTempcardlist\u rst.next())
this.noOfRecords=assignedtempcardlist_rst.getInt(1);
}捕获(例外情况除外){
例如printStackTrace();
}最后{
试一试{
closeConnection(连接,null,null);
}捕获(例外情况除外){
例如printStackTrace();
}
}
}
返回临时卡片列表;
}
我使用它进行分页,这是我在jsp/servlet中完成的
当我使用这个选择find_ROWS()
时,它返回1
同时,当我使用这个查询时:从acct_tempcardhistory中选择COUNT(empid)代码>
它给出了期望的输出,但当我进行过滤时,值不正确
如何解决这个问题,请帮帮我
谢谢和问候你可以这样试试
PreparedStatement noOfRecordsPS = connection.prepareStatement("SELECT FOUND_ROWS() FROM acct_tempcardhistory;");
你可以这样试试
PreparedStatement noOfRecordsPS = connection.prepareStatement("SELECT FOUND_ROWS() FROM acct_tempcardhistory;");
相关的相关的