Click to See Complete Forum and Search --> : Displaying data from mysql database.


guravharsha
07-08-2008, 08:36 AM
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

chazzy
07-08-2008, 09:04 AM
are you initializing Statement st to anything but null somewhere? are you getting a connection?

guravharsha
07-08-2008, 09:13 AM
Hi,
Kindly provide solution for above?
Regards
haresh

Khalid Ali
07-08-2008, 03:27 PM
as chazzy pointed out.
1. You need to create a Connection to your database
2. Then you need to create a statement using that connection
3. Only after that you will be able to get a Resultset.
Take a look at the sticky at the top of the forum, I think I created an example on how to connect to MySQL db