Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Display Database Values in Javascript table

 
Ananth sunraj
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jack Doson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();

request.setAttribute("result",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();
rs.next();%>

html code

<%=rs.getString(1)%>[by using expression evaluter..!]
html code
<%=rs.getString(2)%>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic