File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

database with jsp

 
Madhawi Maurya
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How we presant the database values on JSP pages?
 
rahul khanna
Ranch Hand
Posts: 48
  • 0
  • 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..
 
Meenal Srivastva
Greenhorn
Posts: 19
  • 0
  • 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>
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • 0
  • 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
  • 0
  • 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..
 
mihir maniar
Ranch Hand
Posts: 88
  • 0
  • 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.
 
Qussay Najjar
Ranch Hand
Posts: 53
  • 0
  • 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...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic