944,008 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 5130
  • JSP RSS
Apr 27th, 2006
0

URGENT: JSP - StackOverFlow Error

Expand Post »
Hi All!

I've been working on a simple MVC style / struts web application which will allow a user to view a product database and have the option to update a record. The initial index.jsp page works and forwards to the right locations, the update page displays but is producing another error but that is not within the scope of this question.

When i click to view the product database, I get the following error in Apache Tomcat (note I am using built in Tomcat within Netbeans 5.0)

I have done searches on the Web and they say that this method is being called recursively? However, when I run a System.out.println to show the SQL query it displays fine with no problems. Also it is not showing errors with other methods, so I assume that it is stuck on this getPid method.

I hope someone can shed some light on this matter.

Thanks

Apache Tomcat Error

HTTP Status 500 -

type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781) org.apache.jsp.viewprod_jsp._jspService(viewprod_jsp.java:112) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362) org.apache.struts.action.ActionServlet.processForward(ActionServlet.java:1848) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1569) org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:492) javax.servlet.http.HttpServlet.service(HttpServlet.java:689) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
root cause
java.lang.StackOverflowError elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid

.... THIS CONTINUES TILL THE END OF THE PAGE ....

(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid(UpdateBean.java:16) elecstore.UpdateBean.getPid
(UpdateBean.java:16)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
Apache Tomcat/5.5.9


UpdateBean.java

JSP Syntax (Toggle Plain Text)
  1. package elecstore;
  2. import java.sql.*;
  3. import java.sql.Date;
  4. import java.text.*;
  5. import java.util.*;
  6. import javax.naming.*;
  7. import javax.sql.*;
  8. import elecstore.*;
  9. public class UpdateBean {
  10.  
  11. Products p = null;
  12.  
  13. public int getPid() {
  14. return getPid();
  15. }
  16.  
  17. public void setPid(int pid) {
  18. setPid(pid);
  19. }
  20.  
  21. public String getProdId() {
  22. return getProdId();
  23. }
  24.  
  25. public void setProdId (String prodId) {
  26. setProdId(prodId);
  27. }
  28.  
  29. public String getProdType() {
  30. return getProdType();
  31. }
  32.  
  33. public void setProdType (String prodType) {
  34. setProdType(prodType);
  35. }
  36.  
  37. public String getMan() {
  38. return getMan();
  39. }
  40.  
  41. public void setMan (String man) {
  42. setMan(man);
  43. }
  44.  
  45. public String getProduct() {
  46. return getProduct();
  47. }
  48.  
  49. public void setProduct (String product) {
  50. setProduct(product);
  51. }
  52.  
  53. public int getQty() {
  54. return getQty();
  55. }
  56.  
  57. public void setQty (int qty) {
  58. setQty(qty);
  59. }
  60.  
  61. public String getPrice() {
  62. return getPrice();
  63. }
  64.  
  65. public void setPrice (String price) {
  66. setPrice(price);
  67. }
  68.  
  69. public Date getDateAdded() {
  70. return getDateAdded();
  71. }
  72.  
  73. public void setDateAdded (Date dateAdded) {
  74. setDateAdded(dateAdded);
  75. }
  76.  
  77. public boolean getStockOnOrder() {
  78. return getStockOnOrder();
  79. }
  80.  
  81. public void setStockOnOrder (boolean stockOnOrder) {
  82. setStockOnOrder(stockOnOrder);
  83. }
  84.  
  85. public UpdateBean() throws SQLException, NamingException
  86. {
  87. String jdbcDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
  88. String dbURL = "jdbc:odbc:qc310";
  89. String user = "Lukas";
  90. String password = "12345";
  91.  
  92. System.out.println("TEST HERE - UpdateBean");
  93. Connection con = null;
  94. Connection con2 = null;
  95. Statement select = null;
  96. PreparedStatement updateProduct = null;
  97. ResultSet rs = null;;
  98. ResultSet rs2 = null;
  99.  
  100. try {
  101. System.out.println("TEST HERE - making database connection...");
  102. // Load in the JDBC-ODBC driver
  103. Class.forName(jdbcDriver);
  104.  
  105. // Create connection
  106. con = DriverManager.getConnection(dbURL, user, password);
  107. System.out.println("\n...Connection to Electronic Store Database Established\n");
  108. System.out.println("TEST HERE - database connection ok...");
  109.  
  110. Statement stmt = con.createStatement();
  111. System.out.println("SQL Statement created...");
  112. rs = stmt.executeQuery("SELECT * FROM Elecstore");
  113.  
  114.  
  115. while (rs.next()) {
  116.  
  117. p = new Products(rs.getInt(1),
  118. rs.getString(2),
  119. rs.getString(3),
  120. rs.getString(4),
  121. rs.getString(5),
  122. rs.getInt(6),
  123. rs.getString(7),
  124. rs.getDate(8),
  125. rs.getBoolean(9));
  126.  
  127. System.out.println(p.getPid() + " " + p.getProdId() + "\t" + p.getProdType() + "\t\t" + p.getMan() + "\t\t" + p.getProduct() + "\t\t\t" + p.getPrice() + "\t\t\t" + p.getQty() + "\t\t\t" + p.getDateAdded() + "\t\t\t" + p.getStockOnOrder());
  128. }
  129. rs.close();
  130.  
  131. }
  132.  
  133. catch(Exception e) {
  134. e.printStackTrace();;
  135. }
  136.  
  137.  
  138. try {
  139.  
  140. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  141. con2 = DriverManager.getConnection("jdbc:odbc:qc310");
  142. updateProduct = con.prepareStatement("UPDATE Elecstore SET Qty = ?, Price = ? WHERE ProductID = ?");
  143.  
  144. updateProduct.setInt (1, p.getQty());
  145. updateProduct.setString (2, p.getPrice());
  146. updateProduct.setString (3, p.getProdId());
  147.  
  148. updateProduct.executeUpdate();
  149.  
  150. if (!rs2.next())
  151. throw new SQLException("Missing Products data row");
  152.  
  153. }
  154.  
  155. catch(Exception e) {
  156. System.out.println(e);
  157. }
  158.  
  159. finally {
  160. try { rs.close(); } catch (Exception ex) {}
  161. try { con.close(); } catch (Exception ex) {}
  162. }
  163. }
  164. }

Products.java

JSP Syntax (Toggle Plain Text)
  1. package elecstore;
  2. import java.sql.Date;
  3.  
  4. /**
  5.  * This domain object represents a player in a sports league.
  6.  * The data attributes are all package-private to allow access to them
  7.  * in the {@link RegisterService} class.
  8.  */
  9. public class Products {
  10. int pid;
  11. int qty;
  12. String prodId;
  13. String prodType;
  14. String man;
  15. String product;
  16. String price;
  17. Date dateAdded;
  18. boolean stockOnOrder;
  19.  
  20. /**
  21.   * This is the constructor. It is package-private to prevent
  22.   * misuse. The {@link RegisterServer} method should be used to
  23.   * create a new player object.
  24.   */
  25. //Product(String prodID) {
  26. // this(+1, "", prodID, "", "", "", "");
  27. //}
  28. /**
  29.   * This is the full constructor.
  30.   */
  31.  
  32. Products(int pid, String prodId, String prodType, String man,
  33. String product, int qty, String price, Date dateAdded, boolean stockOnOrder) {
  34.  
  35. this.pid = pid;
  36. this.prodId = prodId;
  37. this.prodType = prodType;
  38. this.man = man;
  39. this.product = product;
  40. this.qty = qty;
  41. this.price = price;
  42. this.dateAdded = dateAdded;
  43. this.stockOnOrder = stockOnOrder;
  44. }
  45. public int getQty() {
  46. return qty;
  47. }
  48.  
  49. public void setQty(int qty){
  50. this.qty = qty;
  51. }
  52.  
  53. public int getPid() {
  54. return pid;
  55. }
  56.  
  57. public void setPid(int pid){
  58. this.pid = pid;
  59. }
  60.  
  61. public String getProdId() {
  62. return prodId;
  63. }
  64.  
  65. public void setProdId(String prodId){
  66. this.prodId = prodId;
  67. }
  68.  
  69. public String getProdType(){
  70. return prodType;
  71. }
  72.  
  73. public void setProdType(){
  74. this.prodType = prodType;
  75. }
  76.  
  77. public String getMan(){
  78. return man;
  79. }
  80. public void setMan(String man){
  81. this.man = man;
  82. }
  83. public String getProduct(){
  84. return product;
  85. }
  86. public void setProduct(String product){
  87. this.product = product;
  88. }
  89.  
  90. public String getPrice(){
  91. return price;
  92. }
  93.  
  94. public void setPrice(String price){
  95. this.price = price;
  96. }
  97. public Date getDateAdded() {
  98. return dateAdded;
  99. }
  100.  
  101. public void setDateAdded(Date dateAdded){
  102. this.dateAdded = dateAdded;
  103. }
  104. public boolean getStockOnOrder() {
  105. return stockOnOrder;
  106. }
  107.  
  108. public void setStockOnOrder(boolean stockOnOrder){
  109. this.stockOnOrder = stockOnOrder;
  110. }
  111. }

ActionUpdate.java

JSP Syntax (Toggle Plain Text)
  1. package elecstore;
  2. import java.io.*;
  3. import java.sql.*;
  4. import java.text.*;
  5. import javax.naming.*;
  6. import javax.servlet.*;
  7. import javax.servlet.http.*;
  8. import org.apache.struts.action.*;
  9. import elecstore.*;
  10. import elecstore.UpdateBean;
  11. public class ActionUpdate extends Action
  12. {
  13. public ActionForward perform(ActionMapping mapping, ActionForm actionForm,
  14. HttpServletRequest request, HttpServletResponse response)
  15. throws IOException, ServletException {
  16.  
  17. ActionErrors errors = null;
  18. try {
  19. UpdateBean update = new UpdateBean();
  20. UpdateForm form = (UpdateForm)actionForm;
  21.  
  22. System.out.println(form.getProdId());
  23. update.setProdId(form.getProdId());
  24.  
  25. System.out.println(form.getQty());
  26. update.setQty(form.getQty());
  27.  
  28. System.out.println(form.getPrice());
  29. update.setPrice(form.getPrice());
  30.  
  31. request.setAttribute("prodId",update.getProdId());
  32. request.setAttribute("qty", new Integer(update.getQty()));
  33. request.setAttribute("price",update.getPrice());
  34. return mapping.findForward("update");
  35. }
  36.  
  37. catch (NamingException ex) {
  38. errors = new ActionErrors();
  39. errors.add("database", new ActionError("errors.naming.error"));
  40. }
  41. catch (SQLException ex) {
  42. errors = new ActionErrors();
  43. errors.add("database", new ActionError("errors.database.error"));
  44. }
  45. catch (Exception e) {
  46. System.out.println("AN OTHER" + e);
  47. }
  48. saveErrors(request,errors);
  49. return mapping.findForward("error");
  50. }
  51. }

UpdateForm.java

JSP Syntax (Toggle Plain Text)
  1. package elecstore;
  2. import javax.servlet.http.*;
  3. import org.apache.struts.action.*;
  4. public class UpdateForm extends ActionForm {
  5. private String prodId;
  6. private String price;
  7. private int qty;
  8.  
  9. public void setProdId (String prodId) { this.prodId = prodId; }
  10. public String getProdId () { return prodId; }
  11.  
  12. public void setPrice (String price) { this.price = price; }
  13. public String getPrice () { return price; }
  14. public void setQty (int qty) { this.qty = qty; }
  15. public int getQty () { return qty; }
  16. public void reset(ActionMapping mapping, HttpServletRequest request) {
  17. prodId = null;
  18. price = null;
  19. qty = 0;
  20. }
  21. public ActionErrors validate(ActionMapping mapping,
  22. HttpServletRequest request) {
  23.  
  24. ActionErrors errors = new ActionErrors();
  25. if (prodId == null)
  26. errors.add("prodId", new ActionError("errors.prodId.required"));
  27.  
  28. else if (prodId.length() == 0)
  29. errors.add("prodId", new ActionError("errors.prodId.novalue"));
  30. else if (price == null)
  31. errors.add("price", new ActionError("errors.price.required"));
  32.  
  33. else if (price.length() == 0)
  34. errors.add("price", new ActionError("errors.price.novalue"));
  35.  
  36. else if (qty == 0)
  37. errors.add("qty", new ActionError("errors.qty.required"));
  38.  
  39. return errors;
  40. }
  41.  
  42. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lwinn213 is offline Offline
8 posts
since Apr 2006
Apr 27th, 2006
0

Re: URGENT: JSP - StackOverFlow Error

UPDATE

Here are the Jsp files, after some debugging both pages display, just when I add in the jsp:getproperty then I get the StackOverflowError.

How can i get the JSP to use these values but not cause this Overflow error?

index.jsp

JSP Syntax (Toggle Plain Text)
  1. <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
  2. <html:html locale="true">
  3. <head>
  4. <title>Electronic Store | Admin</title>
  5. <link href="qc310.css" rel="stylesheet" type="text/css">
  6. </head>
  7. <body>
  8. <table border='0' cellspacing='0' cellpadding='0' width='600'>
  9. <tr>
  10. <td colspan='2' bgcolor='#CCCCCC' align='center'><b>Electronic Store</b></td>
  11. </tr>
  12. </table>
  13. <br /><html:link page='/viewprod.do'>View product list</html:link>
  14. <br /><html:link page='/update.do'>Update product</html:link>
  15. <br />
  16. <br />
  17. <table width="600" border="0">
  18. <tr>
  19. <th scope="row">______________________________________________________</th>
  20. </tr>
  21. </table>
  22. <table border='0' cellspacing='0' cellpadding='0' width='600'>
  23. <tr>
  24. <td colspan='2' align='center'><div align="left"><span class="copyright">&copy; 2006 Lukas Winn</span><br />
  25. <br />
  26. </div></td>
  27. </tr>
  28. </table>
  29. <p>&nbsp;</p>
  30. </body>
  31. </html:html>
  32. </html>

viewprod.jsp (without jsp:getproperty set)

JSP Syntax (Toggle Plain Text)
  1. <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
  2. <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
  3. <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
  4. <jsp:useBean id="select" class="elecstore.SelectBean">
  5. <jsp:setProperty name="select" property="pid" />
  6. <jsp:setProperty name="select" property="prodId" />
  7. <jsp:setProperty name="select" property="prodType" />
  8. <jsp:setProperty name="select" property="man" />
  9. <jsp:setProperty name="select" property="product" />
  10. <jsp:setProperty name="select" property="qty" />
  11. <jsp:setProperty name="select" property="price" />
  12. <jsp:setProperty name="select" property="dateAdded" />
  13. <jsp:setProperty name="select" property="stockOnOrder" />
  14. </jsp:useBean>
  15. <html:html>
  16. <head>
  17. <title>Electronic Store | View Product Database</title>
  18. <link href="qc310.css" rel="stylesheet" type="text/css">
  19. </head>
  20. <body>
  21. <h1>Product Database</H1>
  22. <h2>
  23. Products:
  24.  
  25.  
  26. </h2>
  27. <P><html:link page="/home.do">back to main...</html:link></p>
  28. </body>
  29. </html:html>

viewprod.jsp (with jsp:getproperty set)
(THIS IS WHERE THE STACKOVERFLOW OCCURS...)

JSP Syntax (Toggle Plain Text)
  1. <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
  2. <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
  3. <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
  4. <jsp:useBean id="select" class="elecstore.SelectBean">
  5. <jsp:setProperty name="select" property="pid" />
  6. <jsp:setProperty name="select" property="prodId" />
  7. <jsp:setProperty name="select" property="prodType" />
  8. <jsp:setProperty name="select" property="man" />
  9. <jsp:setProperty name="select" property="product" />
  10. <jsp:setProperty name="select" property="qty" />
  11. <jsp:setProperty name="select" property="price" />
  12. <jsp:setProperty name="select" property="dateAdded" />
  13. <jsp:setProperty name="select" property="stockOnOrder" />
  14. </jsp:useBean>
  15. <html:html>
  16. <head>
  17. <title>Electronic Store | View Product Database</title>
  18. <link href="qc310.css" rel="stylesheet" type="text/css">
  19. </head>
  20. <body>
  21. <h1>Product Database</H1>
  22. <h2>
  23. Products:
  24. <jsp:getProperty name="update" property="pid" /><br />
  25. <jsp:getProperty name="update" property="prodId" /><br />
  26. <jsp:getProperty name="update" property="prodType" /><br />
  27. <jsp:getProperty name="update" property="man" /><br />
  28. <jsp:getProperty name="update" property="product" /><br />
  29. <jsp:getProperty name="update" property="qty" /><br />
  30. <jsp:getProperty name="update" property="price" /><br />
  31. <jsp:getProperty name="update" property="dateAdded" /><br />
  32. <jsp:getProperty name="update" property="stockOnOrder" /><br />
  33.  
  34. </h2>
  35. <P><html:link page="/home.do">back to main...</html:link></p>
  36. </body>
  37. </html:html>

update.jsp

JSP Syntax (Toggle Plain Text)
  1. <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
  2. <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
  3. <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
  4. <html:html locale="true">
  5. <head>
  6. <title>Electronic Store | Update Product</title>
  7. <link href="qc310.css" rel="stylesheet" type="text/css">
  8. </head>
  9. <body>
  10. <html:form action="/update.do">
  11. <br /><br /><b>Electronic Store | Update Database</b><br /><br />
  12. Please enter the updated information and then click on update to make the changes to the database<br />
  13. <form action="update.jsp" method="post" name="updateForm" id="updateForm">
  14. <table width="300" border="0">
  15. <tr>
  16. <th width="132" scope="row"><div align="left">Product ID</div></th>
  17. <td width="147"><html:text property="prodId" /></td>
  18. </tr>
  19. <tr>
  20. <th scope="row"><div align="left">Qty</div></th>
  21. <td><html:text property="qty" /></td>
  22. </tr>
  23. <tr>
  24. <th scope="row"><div align="left">Price</div></th>
  25. <td><html:text property="price" /></td>
  26. </tr>
  27. <tr>
  28. <th colspan="2" scope="row"><div align="left"><br />
  29. <html:submit> Update</html:submit>
  30. </div></th>
  31. </tr>
  32. <tr>
  33. <th colspan="2" scope="row">_____________________________________</th>
  34. </tr>
  35. </table>
  36. </form>
  37. <br />
  38. </html:form>
  39. <html:errors/>
  40. <logic:present name="prodId">
  41. Output
  42. <br /><bean:write name="prodId"/>
  43. <br /><bean:write name="price"/>
  44. <br /><bean:write name="qty"/>
  45. </logic:present>
  46. <html:link page="/home.do">back to main... </html:link><br /><br />
  47. <table width="300" border="0">
  48. <tr>
  49. <th scope="row">_____________________________________</th>
  50. </tr>
  51. <tr>
  52. <th scope="row"><div align="left"><span class="copyright">&copy; 2006 Lukas Winn</span></div></th>
  53. </tr>
  54. </table>
  55. <br />
  56. <br />
  57. <br />
  58. </body>
  59. </html:html>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lwinn213 is offline Offline
8 posts
since Apr 2006
May 2nd, 2006
0

Re: URGENT: JSP - StackOverFlow Error

Uhm ...

Look at your UpdateBean code. All of your get/set routines do
nothing but call themselves. They should actually return/set something
from the actual Bean, not just simply call themselves.

When all they do is call themselves, you have a classic case of infinite
recursion.

I assume you meant to call routines of the same name from the p
instance. If this is the case, you forgot to put "p." in front of the
subroutine calls inside of your set/get routines.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
May 5th, 2006
0

Re: URGENT: JSP - StackOverFlow Error

Thanks for that advice, yes I changed that in my code and I got a result, but it is only returning the last record information. Even though the System.out.println displays all records. How would you do it for displaying in the JSP? As I said only the last record data is being shown?

Any ideas?

Selectbean.java

JSP Syntax (Toggle Plain Text)
  1. /*
  2.  * SelectBean.java
  3.  *
  4.  * Created on 28 April 2006, 00:28
  5.  *
  6.  * To change this template, choose Tools | Template Manager
  7.  * and open the template in the editor.
  8.  */
  9. package elecstore;
  10. import java.sql.*;
  11. import java.sql.Date;
  12. import java.text.*;
  13. import java.util.*;
  14. import javax.naming.*;
  15. import javax.sql.*;
  16. import elecstore.*;
  17. public class SelectBean {
  18.  
  19. Products p = null;
  20.  
  21. public int getPid() {
  22. return p.getPid();
  23. }
  24.  
  25. public void setPid(int pid) {
  26. p.setPid(pid);
  27. }
  28.  
  29. public String getProdId() {
  30. return p.getProdId();
  31. }
  32.  
  33. public void setProdId (String prodId) {
  34. p.setProdId(prodId);
  35. }
  36.  
  37. public String getProdType() {
  38. return p.getProdType();
  39. }
  40.  
  41. public void setProdType (String prodType) {
  42. p.setProdType(prodType);
  43. }
  44.  
  45. public String getMan() {
  46. return p.getMan();
  47. }
  48.  
  49. public void setMan (String man) {
  50. p.setMan(man);
  51. }
  52.  
  53. public String getProduct() {
  54. return p.getProduct();
  55. }
  56.  
  57. public void setProduct (String product) {
  58. p.setProduct(product);
  59. }
  60.  
  61. public int getQty() {
  62. return p.getQty();
  63. }
  64.  
  65. public void setQty (int qty) {
  66. p.setQty(qty);
  67. }
  68.  
  69. public String getPrice() {
  70. return p.getPrice();
  71. }
  72.  
  73. public void setPrice (String price) {
  74. p.setPrice(price);
  75. }
  76.  
  77. public Date getDateAdded() {
  78. return p.getDateAdded();
  79. }
  80.  
  81. public void setDateAdded (Date dateAdded) {
  82. p.setDateAdded(dateAdded);
  83. }
  84.  
  85. public boolean getStockOnOrder() {
  86. return p.getStockOnOrder();
  87. }
  88.  
  89. public void setStockOnOrder (boolean stockOnOrder) {
  90. p.setStockOnOrder(stockOnOrder);
  91. }
  92.  
  93. /** Creates a new instance of SelectBean */
  94. public SelectBean() throws SQLException, NamingException
  95. {
  96. String jdbcDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
  97. String dbURL = "jdbc:odbc:qc310";
  98. String user = "Lukas";
  99. String password = "12345";
  100.  
  101. System.out.println("TEST HERE - SelectBean");
  102. Connection con = null;
  103. Statement select = null;
  104. ResultSet rs = null;
  105.  
  106. try {
  107. System.out.println("TEST HERE - making database connection...");
  108. // Load in the JDBC-ODBC driver
  109. Class.forName(jdbcDriver);
  110.  
  111. // Create connection
  112. con = DriverManager.getConnection(dbURL, user, password);
  113. System.out.println("\n...Connection to Electronic Store Database Established\n");
  114. System.out.println("TEST HERE - database connection ok...");
  115.  
  116. Statement stmt = con.createStatement();
  117. System.out.println("SQL Statement created...");
  118. rs = stmt.executeQuery("SELECT * FROM Elecstore");
  119.  
  120. while (rs.next()) {
  121.  
  122. p = new Products(rs.getInt(1),
  123. rs.getString(2),
  124. rs.getString(3),
  125. rs.getString(4),
  126. rs.getString(5),
  127. rs.getInt(6),
  128. rs.getString(7),
  129. rs.getDate(8),
  130. rs.getBoolean(9));
  131.  
  132. System.out.println(p.getPid() + " " + p.getProdId() + "\t" + p.getProdType() + "\t\t" + p.getMan() + "\t\t" + p.getProduct() + "\t\t\t" + p.getPrice() + "\t\t\t" + p.getQty() + "\t\t\t" + p.getDateAdded() + "\t\t\t" + p.getStockOnOrder());
  133. }
  134. System.out.print("After Select query has been run...");
  135. }
  136.  
  137. catch(Exception e) {
  138. e.printStackTrace();;
  139. }
  140.  
  141. finally {
  142. try { rs.close(); } catch (Exception ex) {}
  143. try { con.close(); } catch (Exception ex) {}
  144. }
  145.  
  146. }
  147.  
  148. }

viewprod.jsp

JSP Syntax (Toggle Plain Text)
  1. <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
  2. <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
  3. <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
  4. <jsp:useBean id="select" class="elecstore.SelectBean">
  5. <jsp:setProperty name="select" property="pid" />
  6. <jsp:setProperty name="select" property="prodId" />
  7. <jsp:setProperty name="select" property="prodType" />
  8. <jsp:setProperty name="select" property="man" />
  9. <jsp:setProperty name="select" property="product" />
  10. <jsp:setProperty name="select" property="qty" />
  11. <jsp:setProperty name="select" property="price" />
  12. <jsp:setProperty name="select" property="dateAdded" />
  13. <jsp:setProperty name="select" property="stockOnOrder" />
  14. </jsp:useBean>
  15. <html:html>
  16. <head>
  17. <title>Electronic Store | View Product Database</title>
  18. <link href="qc310.css" rel="stylesheet" type="text/css">
  19. </head>
  20. <body>
  21. <h1>Product Database</H1>
  22. <h2>
  23. Products:
  24. <jsp:getProperty name="select" property="pid" /><br />
  25. <jsp:getProperty name="select" property="prodId" /><br />
  26. <jsp:getProperty name="select" property="prodType" /><br />
  27. <jsp:getProperty name="select" property="man" /><br />
  28. <jsp:getProperty name="select" property="product" /><br />
  29. <jsp:getProperty name="select" property="qty" /><br />
  30. <jsp:getProperty name="select" property="price" /><br />
  31. <jsp:getProperty name="select" property="dateAdded" /><br />
  32. <jsp:getProperty name="select" property="stockOnOrder" /><br />
  33.  
  34.  
  35. </h2>
  36. <P><html:link page="/home.do">back to main...</html:link></p>
  37. </body>
  38. </html:html>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lwinn213 is offline Offline
8 posts
since Apr 2006
May 6th, 2006
0

Re: URGENT: JSP - StackOverFlow Error

In your while (rs.next( ) ) loop, you are recreating "p" everytime.
So, only the last line is available. You would need to use some sort of
Collection (ArrayList probably) to be able to store all the records, but
then, you would also have to figure out a way determine which record
you wish to return the data for. Also, your jsp is currently only set up
to show one record as well. Building the table you want is going take
a bit more planning. Look into JSTL loops and, probably, a more
direct database query.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006

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: connecting jsp with oracle database
Next Thread in JSP Forum Timeline: error due to accessing database connection using jsp





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


Follow us on Twitter


© 2011 DaniWeb® LLC