943,095 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 1039
  • JSP RSS
Mar 10th, 2010
0

jsp table

Expand Post »
hi

i am new to jsp, i need to create a jsp page that has list All,

Add, Delete, Update button, the page should display all the records from the database when list All button is clicked and adds new record when add button is clicked and so on,

is there any way using struts here?
can any one help me plz..


i have already created a jsp page .it retrieves all record from the DB.
JSP Syntax (Toggle Plain Text)
  1. <%@page contentType="text/html"%>
  2. <%@page pageEncoding="UTF-8"%>
  3. <%@page import="java.sql.*, javax.sql.*, javax.naming.*,javax.naming.NamingException"%>
  4. <html>
  5. <head>
  6. <title></title>
  7. </head>
  8. <body>
  9. <%
  10. DataSource ds = null;
  11. Connection conn = null;
  12. ResultSet result = null;
  13. Statement stmt = null;
  14. ResultSetMetaData rsmd = null;
  15. try{
  16. Context context = new InitialContext();
  17. if(context==null)
  18. {throw new RuntimeException("no jndi");}
  19. Context envCtx = (Context) context.lookup("java:comp/env");
  20. ds = (DataSource)envCtx.lookup("testjndi");
  21.  
  22. // ds = getTestjndi();
  23. if (ds != null) {
  24. conn = ds.getConnection();
  25. stmt = conn.createStatement();
  26. result = stmt.executeQuery("select * from \"ADMIN\".\"patient\" where p_age=5");
  27. }
  28. }
  29. catch (SQLException e) {
  30. System.out.println("Error occurred " + e);
  31. }
  32. int columns=0;
  33. try {
  34. rsmd = result.getMetaData();
  35. columns = rsmd.getColumnCount();
  36. }
  37. catch (SQLException e) {
  38. System.out.println("Error occurred " + e);
  39. }
  40. %>
  41. <table width="90%" border="1">
  42. <tr>
  43. <% // write out the header cells containing the column labels
  44. try {
  45. for (int i=1; i<=columns; i++) {
  46. out.write("<th>" + rsmd.getColumnLabel(i) + "</th>");
  47. }
  48. %>
  49. </tr>
  50. <% // now write out one row for each entry in the database table
  51. while (result.next()) {
  52. out.write("<tr>");
  53. for (int i=1; i<=columns; i++) {
  54. out.write("<td>" + result.getString(i) + "</td>");
  55. }
  56. out.write("</tr>");
  57. }
  58.  
  59. // close the connection, resultset, and the statement
  60. result.close();
  61. stmt.close();
  62. conn.close();
  63. } // end of the try block
  64. catch (SQLException e) {
  65. System.out.println("Error " + e);
  66. }
  67. // ensure everything is closed
  68. finally {
  69. try {
  70. if (stmt != null)
  71. stmt.close();
  72. } catch (SQLException e) {}
  73. try {
  74. if (conn != null)
  75. conn.close();
  76. } catch (SQLException e) {}
  77. }
  78.  
  79. %>
  80. </table>
  81. </body>
  82. </html>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
karthickj25 is offline Offline
3 posts
since Mar 2010
Mar 11th, 2010
0
Re: jsp table
with struts have you seen logic tags..

<logic:iterate>
</logic:iterate>
Reputation Points: 19
Solved Threads: 45
Posting Whiz
musthafa.aj is offline Offline
312 posts
since Nov 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: Problem while upgrading to tomcat 6.0.20
Next Thread in JSP Forum Timeline: how can i update JSP page itself





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC