error :java.lang.NullPointerException in searchuser.jsp page

Thread Solved

Join Date: Jun 2008
Posts: 38
Reputation: guravharsha is an unknown quantity at this point 
Solved Threads: 0
guravharsha guravharsha is offline Offline
Light Poster

error :java.lang.NullPointerException in searchuser.jsp page

 
0
  #1
Jul 10th, 2008
Hi,
I am creating the updateuser.jsp page. For that I create search.jsp where one can serch users and after submitting this page.it should display the updateuser.jsp page where I can update the details of user. Here is my code of searchuser.jsp:
  1. <% Connection connection = null;
  2. Statement st = null;
  3. ResultSet rs = null;
  4. Class.forName("com.mysql.jdbc.Driver");
  5. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mynewdatabase","root", "root123");
  6. [COLOR="Red"]/// st=connection.createStatement();///[/COLOR]
  7. try {
  8. rs = st.executeQuery("Select * from user order by useid Asc");
  9. while (rs.next())
  10. {
  11. %>
  12. <option value = "<%=rs.getString("userid")%>" >
  13. <%=rs.getString("emailid") + " "+rs.getString("groupid")%>
  14. </option>
  15. <%
  16. }
  17.  
  18. }
  19. finally
  20. {
  21. if (rs != null)
  22. {
  23. rs.close();
  24. rs = null;
  25. }
  26. if (st != null)
  27. {
  28. st.close();
  29. st = null;
  30. }
  31.  
  32. }
  33. %>
but shows error at above marked line as:

java.lang.NullPointerException
org.apache.jsp.searchuser_jsp._jspService(searchuser_jsp.java:91)

Well, whether it is right way to retrive data and shows to user?
Any suggestion is highly appreciated.
Thanks and Regards
Haresh
Last edited by peter_budo; Jul 10th, 2008 at 5:28 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,182
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 481
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: error :java.lang.NullPointerException in searchuser.jsp page

 
0
  #2
Jul 10th, 2008
Of course it will, you declares connections as
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mynewdatabase","root", "root123");
but you trying to call it as
st=connection.createStatement();

You should seriously look into some materials on Java web development Java EE5 Tutorial and JDBC Database Access may help you too. As I said previously accessing database from JSP is bad thing to do
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC