File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Displaying database info in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Displaying database info in JSP" Watch "Displaying database info in JSP" New topic

Displaying database info in JSP

Aniketh Narayanan

Joined: Jan 05, 2013
Posts: 12
I am working on a project where i am using jsp and servlets.
I am retrieving data from the database and displaying it in a table.
When i click on the respective ID, it should take me to a page where I can edit the fields.
This, is the code i have written..


Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

try {
conn= DriverManager.getConnection("jdbcdbc:resourcedetails1");
rs=stmt.executeQuery("select * from resourcedetails");
<tr><td><a href="prjinsert.jsp"><%=rs.getString("EmployeeID")%></a></td><td><a href="prjinsert.jsp"><%=rs.getString("EmplyeeName")%></a></td><td><%=rs.getDate("DOJSyntel")%></td>


catch(Exception e){e.printStackTrace();}

The place where i am stuck is, how do i send the ID clicked by the user to the servlet so that, that particular details can be retrieved in the appropriate fields in the next page ?

Please help.

Vijay Vishwa
Ranch Hand

Joined: Nov 21, 2010
Posts: 32
Hi Aniketh, please use the code tag on the tool bar for the code snippet which could help in reading
Am doing it for you now.

SCJP 5.0 OCBCD 5.0(Formerly SCBCD)
Vijay Vishwa
Ranch Hand

Joined: Nov 21, 2010
Posts: 32
Regarding you question..

Have the table in the form

In prjinsert.jsp use

to get the selected EmployeeID.

Also try to use MVC architecture for designing the application. This will make your project more maintainable.
Aniketh Narayanan

Joined: Jan 05, 2013
Posts: 12
Thank you so much for your help.

But whenever i write the code...

<a href="prjinsert.jsp?EID=<%=rs.getString("EmployeeID")%>"><%=rs.getString("EmployeeID")%></a>

It does not retrieve any value from the database.
It gives me blank rows

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63540

You should not be writing Java code in a JSP. Java code should be in Java classes. The servlet controller should send the data to the JSP as a List or other not-a-result-set format.

Please read this article for how to properly structure web applications.

[Asking smart questions] [About Bear] [Books by Bear]
Vijay Vishwa
Ranch Hand

Joined: Nov 21, 2010
Posts: 32
Print the value of

in the logs. See if any value is beeing passed.

also need to see the code to comments anything.
Aniketh Narayanan

Joined: Jan 05, 2013
Posts: 12

Here is the code.
For me to check the passing of the parameter, the link itself is not appearing.
And when i directly write

It retrieves the values properly.
I agree. Here's the link:
subject: Displaying database info in JSP
It's not a secret anymore!