Note that there are some explanatory texts on larger screens.

plurals
  1. POSELECT FOUND_ROWS() always returns ONE, How to solve this
    primarykey
    data
    text
    <p>the following sql always returns <code>one</code> <code>SELECT FOUND_ROWS()</code></p> <p>i have followed this example from net : </p> <pre><code>public List&lt;Employee&gt; viewAllEmployees( int offset, int noOfRecords) { String query = "select SQL_CALC_FOUND_ROWS * from employee limit " + offset + ", " + noOfRecords; List&lt;Employee&gt; list = new ArrayList&lt;Employee&gt;(); 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; } </code></pre> <p>and this is my code based on the above : </p> <pre><code>public List&lt;TempcardViewModel&gt; getTempcardHistory(String query) { TempcardViewModel tempcardObj = null; List&lt;TempcardViewModel&gt; tempcardList = new ArrayList&lt;TempcardViewModel&gt;(); 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; } </code></pre> <p>I am using this for paging which i have done in jsp/servlets.</p> <p>when i use this <code>SELECT FOUND_ROWS()</code> it returns <code>1</code></p> <p>at the same time when i use this query : <code>SELECT COUNT(empid) FROM acct_tempcardhistory;</code></p> <p>it gives desired out put but when i go for filtering than the values are not correct.</p> <p>how to solve this, Please help me.</p> <p>thanks and regards</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload