Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying database info in JSP

 
Aniketh Narayanan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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 {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn= DriverManager.getConnection("jdbcdbc:resourcedetails1");
stmt=conn.createStatement();
rs=stmt.executeQuery("select * from resourcedetails");
while(rs.next()){
%>
<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>
<td><%=rs.getDate("DOJRCIX")%></td><td><%=rs.getString("EmailID")%></td>
<td><%=rs.getString("DateofBirth")%></td></tr>

<%
}

rs.close();
stmt.close();
conn.close();
}
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.

Thankyou
 
Vijay Vishwa
Ranch Hand
Posts: 40
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vijay Vishwa
Ranch Hand
Posts: 40
1
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much for your help.

But whenever i write the code...

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

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

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65223
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vijay Vishwa
Ranch Hand
Posts: 40
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic