Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes JDBC and Relational Databases and the fly likes displaying data from mysql database. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "displaying data from mysql database." Watch "displaying data from mysql database." New topic

displaying data from mysql database.

Harshal Gurav
Ranch Hand

Joined: May 29, 2008
Posts: 151
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")%>" >
when i run the above code it shows the error:
like rs=st.execute....
can anybody have solution for above or any alternative code.
Thanks and regards
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

You shouldn't be doing JDBC code in a JSP. That's a very bad practice.

But how can you look at the following two lines of code:

and not see how that will create a null pointer exception?

I've moved this to the JDBC forum as it has nothing to do with JSP.

[Asking smart questions] [About Bear] [Books by Bear]
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
As breat told we are not supposed to use Jdbc code in Jsp.

If you would like to retrive the data from a table(irrespective or database).

These things are manadatory.

1. Importing the package. import java.sql.*;

2. Loading the Driver Class.forName("the driver class which yu want to use");

3. Connecting to database

Connection con=DriverManager.getConnection(URL);
4. Creatign the statement(which you did not do)

Statement st=con.createStatement();

5. Query

for trasactional query
ResultSet ra=st.executeQuery("select..");
6. Close the connection.

SCJP 1.4 & 1.5, SCWCD 1.5. Learn and Let Learn.
I agree. Here's the link:
subject: displaying data from mysql database.
It's not a secret anymore!