Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting Null value from attribute
    primarykey
    data
    text
    <p>In the Dynamic web application I facing some issues,so I'm posting my code:</p> <p>Here is my controller(servlet):</p> <pre><code> String select = request.getParameter("select"); // getting proper value String search = request.getParameter("search"); // getting proper value request.setAttribute("select", select); request.setAttribute("search", search); System.out.println("Select : "+select+" Search : "+search); int page = 1; int recordsPerPage = 20; if(request.getParameter("page") != null) page = Integer.parseInt(request.getParameter("page")); SearchDAO searchDAO=new SearchDAO(); List&lt;User&gt; list=searchDAO.searchAllUsers((page-1)*recordsPerPage,recordsPerPage,select,search); int noOfRecords = searchDAO.getNoOfRecords(); System.out.println("4&gt; NoOfRecords : "+noOfRecords); int noOfPages = (int) Math.ceil(noOfRecords * 1.0 / recordsPerPage); System.out.println("5&gt; NoOfPages : "+noOfPages); request.setAttribute("searchList", list); System.out.println("6&gt; List : "+list); request.setAttribute("noOfPages", noOfPages); // Getting null value, 0 request.setAttribute("currentPage", page); // Getting null value, 0 RequestDispatcher view = request.getRequestDispatcher("/jsp/Securex_Anti_Theft_SearchUserList.jsp"); view.forward(request, response); </code></pre> <p>And here is my DAO (simple java class):</p> <pre><code>public class SearchDAO { private int noOfRecords; Connection connection; Statement stmt; public List&lt;User&gt; searchAllUsers(int offset ,int noOfRecords,String select,String search){ private static Connection getConnection() throws SQLException,ClassNotFoundException{ Connection con = ConnectionFactory.getInstance().getConnection(); return con; //ConnectionFactory is class for making the connection to DB. } String query="select SQL_CALC_FOUND_ROWS * from info where '"+select+ "' like '%"+search+"%' order by serialNo asc limit " + offset + " , " + noOfRecords; List&lt;User&gt; list1 = new ArrayList&lt;User&gt;(); User user1=null; try { connection = getConnection(); stmt = connection.createStatement(); ResultSet rs=stmt.executeQuery(query); System.out.println("1&gt; :"+rs); while(rs.next()){ user1=new User(); user1.setSerial(rs.getInt(1)); System.out.println("I'm inside a loop"); user1.setName(rs.getString(2)); user1.setEmail(rs.getString(3)); list1.add(user1); } rs.close(); rs = stmt.executeQuery("SELECT FOUND_ROWS()"); System.out.println("2&gt; :" +rs); if(rs.next()) this.noOfRecords = rs.getInt(1); System.out.println("3&gt; :" +this.noOfRecords); } 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 list1; } public int getNoOfRecords() { return noOfRecords; } } </code></pre> <p>And the Output is : </p> <pre><code>1&gt; :com.mysql.jdbc.JDBC4ResultSet@1af8502 2&gt; :com.mysql.jdbc.JDBC4ResultSet@455aa8 3&gt; :0 4&gt; NoOfRecords : 0 5&gt; NoOfPages : 0 6&gt; List : [] </code></pre> <p>I have same same servlet and class for select all users,and that's working properly,bbut getting null value from here.Even ResultSet returns value i.e. com.mysql.jdbc.JDBC4ResultSet@88d319,but unable fetch the value from DAO to servlet.</p> <p>Getting null value from <code>//</code> attributes,To me everything should be going fine but still getting null value,feel free to point out my mistake,If I have done anything</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.
 

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