Hi,
In main.jsp i wish to display the data from the database( user information stored in user table ). my codein main.jsp is:

<h2> description about user:</h2>
<% Statement st = null;
ResultSet rs = null;

rs = st.executeQuery("Select description from user ");
%>
<option value = "<%=rs.getString("description")%>" >
</option>

when i run the above code it shows the error:

java.lang.NullPointerException
org.apache.jsp.main_jsp._jspService(main_jsp.java:72)

like at abovered color line
can anybody have solution for above or any alternative code.
Thanks and regards
Haresh

Recommended Answers

All 2 Replies

Now I do not know what to say:

Statement st = null;
ResultSet rs = null;

rs = st.executeQuery("Select description from user ");

Sorry If I sound rude, But do you expect some magic ;) , you are calling the method on an object (st) reference set to NULL, even if the sun doesn't rise tomorrow that code is going to throw a NullPointerException.

commented: Sun will rise tomorrow, so there will be NULL +8

One more thing to add, setting up connection with database from JSP is bad thing to do. Learn to use servlets and then do JSF

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.