Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

database with jsp  RSS feed

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How we presant the database values on JSP pages?
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably thousand of ways of doing it ..
simple one ..

get the database result set add that into an object..

add the object to session .

retrieve the object from session on the jsp and display..
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here's some sample code from my application


<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn= DriverManager.getConnection("jdbcdbc:meenal");


statement=conn.createStatement();
rs= rs = statement.executeQuery("SELECT * FROM emp");
%>
<table border="1" width="92%" id="table1">
<tr>
<td width="227" align="center">
<font size="4">Name</font></td>
<td width="200" align="center">
<font size="4">Date Of Birth</font></td>
<td width="112" align="center">
<font size="4">Gender</font></td>
<td width="225" align="center">
<font size="4">Qualification</font></td>
<td align="center">
<font size="4">Location Preference</font></td>
</tr>


<% while (rs.next()) { %>
<tr> <b>
<td width="227" align="center"> <font size="3" >
<%out.println(rs.getObject("name"));%> </font> </td>
<td width="200" align="center"> <font size="3">
<%out.println(rs.getObject("dateOfBirth"));%> </font></td>
<td width="112" align="center"> <font size="3">
<%out.println(rs.getObject("gender"));%> </font> </td>
<td width="225" align="center"> <font size="3">
<%out.println(rs.getObject("qualification"));%> </font></td>
<td align="center"> <font size="3">
<%out.println(rs.getObject("locationPreference"));%> </font></td></b>
</tr>
<% } %>

<%rs.close();
conn.close(); %>


</table>
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many different ways to do this.

Perhaps you can straight away deal with the database related code in jsp, it IS not a better way.

You can implement a MVC like pattern in your page. But for some sample or demo purpose, you are free to use the code to deal with database direclty in a scriptlet!

Does that help?
 
rahul khanna
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably thousand of ways of doing it ..
simple one ..

get the database result set add that into an object..

add the object to session .

retrieve the object from session on the jsp and display..
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well one of the better programming model would be to have a servlet that will call the DAO objects that talk to database and retrieve the values that you want in a POJO (Plain old java object). then store this in the session and call the jsp and from session access this object. i hope this helps you.
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best way I've read about and used is the next as an example:
1- We have a Bean called Employee:


now you have records in the DB for employees (id,name,jobTitle),
let's get these records and display them:

2- A Servlet should do the job of retrieving the records:


It's time for displaying now:

3- In your JSP page:


Hope it helps...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!