File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
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: 63548

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.
jQuery in Action, 3rd edition