File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes How to Display Database Values in Javascript table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to Display Database Values in Javascript table" Watch "How to Display Database Values in Javascript table" New topic

How to Display Database Values in Javascript table

Ananth sunraj

Joined: Sep 05, 2008
Posts: 12
Can anyone suggest me ideas for populating the table with Database values using javascript and Ajax.

Rather than using <td><% rs.getString(1)%></td> like.

Thanks in Advance
Jair Rillo Junior
Ranch Hand

Joined: Aug 27, 2008
Posts: 114
You can use any framework to do that, I like DWR. It is simple and easy to use.

The code to retrieve the data from database will be a Java class, and the AJAX will request those values from this Java code and then display them on the HTML without Scriptlets.

Regards, Jair Rillo Junior, SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 5.0, IBM SOA Associate (Test 664).
Jack Doson

Joined: Oct 02, 2008
Posts: 9
Generally , we are not supposed(adviced) to write Data Base access code inside any Jsp..! Better way is to acces date base in any Bean(other java class) and pass that bean to jsp. access variable of that class in the jsp..!

(general syntax is Instantiate bean in servlet....!

set that bean as a attribute to request object..!
DataBean databean=new DataBean();


inside jsp..
<jsp:useBean id="result" scope="request" class="DataBean"/>
<jsp:getProperty name="result" property="name"/>

Specific Answer to your Question..!

<% Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverMananger.getConncetion("dburl","username","password");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery();;%>

html code

<%=rs.getString(1)%>[by using expression evaluter..!]
html code

Jack Dososn..!
I agree. Here's the link:
subject: How to Display Database Values in Javascript table
jQuery in Action, 3rd edition