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
Forums
Register
Login
Java
»
JSP
HTML table with ajax
Neeraj jain
,
Ranch Hand
Aug 11, 2013 15:14:05
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
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
Aug 11, 2013 23:32:51
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
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>"); }
Neeraj jain
,
Ranch Hand
Aug 12, 2013 02:05:45
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
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
Post by:
autobot
That new kid is a freak. Show him this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
This thread has been viewed 1884 times.
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...
All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:02:14
.