Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search Coderanch
Advance search
Google search
Register / Login
Ayo Babatope
Greenhorn
+ Follow
2
Posts
2
Threads
0
Cows
since Jan 17, 2013
Merit badge:
grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
Ranch Hand Scavenger Hunt
Number Posts (2/100)
Number Threads Started (2/100)
Number Cows Received (0/5)
Number Likes Received (0/10)
Number Likes Granted (0/20)
Set bumper stickers in profile (0/3)
Report a post to the moderators (0/1)
Edit a wiki page (0/1)
Create a post with an image (0/2)
Greenhorn Scavenger Hunt
First Post
Number Posts (2/10)
Number Threads Started (2/10)
Number Likes Received (0/3)
Number Likes Granted (0/3)
Set bumper stickers in profile (0/1)
Set signature in profile
Search for a post/thread (0/3)
Set a watch on a thread
Save thread as a bookmark
Create a post with an image (0/1)
Recent posts by Ayo Babatope
Servlet not populating html table on jsp page
Hello Friends,
I am trying to populate an html table on a jsp page with a servlet that queried a database but it is not populating the table..
Kindly help out..
Servlet Code: Viewall.java
package jcjoofpackage; import java.io.IOException; import java.io.PrintWriter; import java.sql.*; import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.jsp.jstl.sql.Result; import javax.servlet.jsp.jstl.sql.ResultSupport; /** * * @author Omotayo Fisayo */ public class Viewall extends HttpServlet{ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); Connection con = null; Statement stm = null; try{ String url = "jdbc:mysql://localhost:8080/sght"; con = DriverManager.getConnection(url, "**", "**"); stm = con.createStatement(); String query= "select CLIENT_CODE, TERMINAL_NAME, CALL_DATE, CALL_TIME, CALL_DESCRIPTION, CALL_STATUS, CLOSURE_DATE, CLOSURE_TIME, REMARK from logbook"; ResultSet rst = stm.executeQuery(query); int i = 0; while (rst.next()){ Result result = ResultSupport.toResult(rst); request.setAttribute("result", result); RequestDispatcher rd = request.getRequestDispatcher("home.jsp"); rd.forward(request, response); ++i;} } catch (SQLException ex){ throw new ServletException(ex); } finally {try { con.close(); stm.close(); } catch (SQLException ex) { Logger.getLogger(Viewall.class.getName()).log(Level.SEVERE, null, ex); } } } }
jsp code: home.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Home Page</title> </head> <body style=" background-color: #94c3d1"> <table border="0" > <tr> <td><div style="font-size: 15px;"> <a > logout</a></div> </td> <td></td> </tr> </table><hr> <table border="0" > <tbody> <tr><td><form name="view" action="Viewall"> <input type="submit" value="View All" name="Lcall" style="background-color:black; color: white" /> </form></td> </tbody> </table> <table border="1" > <!-- column headers --> <thead> <tr > <th>Client Code</th> <th>Terminal Name</th> <th>Call Date</th> <th>Call Time</th> <th >Call Description</th> <th>Call Status</th> <th>Closure Date</th> <th>Closure Time</th> <th>Remark</th> </tr> </thead> <c:forEach var="row" items="${result.rowsByIndex}" > <tr> <c:forEach var="column" items="${row}"> <td><c:out value="${column}"/></td> </c:forEach> </tr> </c:forEach> </table> </body> </html>
show more
10 years ago
Servlets
JTable not refreshing
My Jtable is not refreshing itself automatically when its data in the database to which it is connected to changed.
But it will refresh when I restart the application.
I'm using my own TableModel that extends AbstractTableModel..
Please help, I want the Jtable to refresh automatically when a change occur to its data in the database.
show more
11 years ago
JDBC and Relational Databases