Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JSP
Search Coderanch
Advance search
Google search
Register / Login
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
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
JSP
HTML table with ajax
Neeraj jain
Ranch Hand
Posts: 108
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
i am making a table which fetches the record from the database but it is fetching only one record i want to show all the records onto the table via ajax so please help me
index.html
<html> <head> <script type="text/javascript"> function loadXMLDoc() { var xmlhttp; var urls="db_fetch.jsp?ok="+100 if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var some=xmlhttp.responseXML.documentElement; document.getElementById("a").innerHTML=some.getElementsByTagName("empno") [0].childNodes[0].nodeValue; document.getElementById("b").innerHTML=some.getElementsByTagName("empname") [0].childNodes[0].nodeValue; } } xmlhttp.open("GET",urls,true); xmlhttp.send(); } </script> </head> <body onload="loadXMLDoc()"> <table border="1" onload="loadXMLDOC()"> <tr> <td width="50px">id:</td><td width="60px">name:</td> </tr> <tr> <td> <span id="a"></span></td> <td> <span id="b"></span></td> </tr> </table> </body> </html>
db_fetch.jsp
<%@ page import="java.io.*,java.sql.*" %> <%@ page contentType="text/html" pageEncoding="UTF-8"%> <% response.setContentType("text/xml"); String sn=request.getParameter("ok"); int i=Integer.parseInt(sn); Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con =DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","ducatWE","abcdef"); Statement st=con.createStatement(); ResultSet rs = st.executeQuery("select * from emp where empno="+i); if(rs.next()) { out.println("<emp>"); out.println("<empno>"+rs.getInt(1)+"</empno>"); out.println("<empname>"+rs.getString(2)+"</empname>"); out.println("</emp>"); } rs.close(); st.close(); con.close(); %>
Arvind Sri
Greenhorn
Posts: 4
I like...
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I think the issue is here. You are only writing the first row in the out stream.
if(rs.next()) { out.println("<emp>"); out.println("<empno>"+rs.getInt(1)+"</empno>"); out.println("<empname>"+rs.getString(2)+"</empname>"); out.println("</emp>"); }
It should be
while(rs.next()) { out.println("<emp>"); out.println("<empno>"+rs.getInt(1)+"</empno>"); out.println("<empname>"+rs.getString(2)+"</empname>"); out.println("</emp>"); }
Cheers !!
- Arvind Srivastava
Neeraj jain
Ranch Hand
Posts: 108
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
@Arvind
i also thought that it is that simple i've alredy tried it but after that not even getting a single record onto my table
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Passing Value from Javascript method into HTML Body
Filter Option on drop down menu
Display / Hide Table based on output
Couldn't find error in this code
Filter UserName by "Ascending/Descending options in drop down menu."
More...