aspose file tools*
The moose likes JSP and the fly likes database with jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "database with jsp" Watch "database with jsp" New topic
Author

database with jsp

Madhawi Maurya
Ranch Hand

Joined: Aug 22, 2007
Posts: 42
How we presant the database values on JSP pages?


SCJP1.5 with 90%
rahul khanna
Ranch Hand

Joined: Sep 14, 2005
Posts: 48
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

Joined: Jan 21, 2007
Posts: 19
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>


Thanks,
Meenal
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

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?


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
rahul khanna
Ranch Hand

Joined: Sep 14, 2005
Posts: 48
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

Joined: Sep 09, 2003
Posts: 88
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

Joined: Jan 18, 2008
Posts: 53
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...


Qussay NAJJAR
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: database with jsp
 
Similar Threads
jsp connection
hi everybody me Epsan new to this Forum,to Java
How to dispaly Blob (image) in servlet
db to jsp
how to set up a navigaeting tree according to the database records?