Page 1 of 2 12 LastLast
Results 1 to 20 of 23
  1. #1
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default In debug a javabean, how check it is giving to other component CORRECT data-DAO/pools

    textbook example 12-3(david pasons java/xml) - DAO / DB-POOL / TOMCAT

    At localhost
    http://localhost:8080/jspadv/webhome...listclaims.jsp
    I do NOT know, how debug? In debug a javabean, how check it is giving to other component CORRECT data?
    The below means not find data ...? in db?

    Java Code:
      org.apache.jasper.JasperException: javax.el.ELException: Error reading 'claims' on type com.webhomecover.beans.ClaimCollection
    	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    
    
    root cause 
    
    javax.el.ELException: Error reading 'claims' on type com.webhomecover.beans.ClaimCollection
    	javax.el.BeanELResolver.getValue(BeanELResolver.java:66)
    	javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
    	org.apache.el.parser.AstValue.getValue(AstValue.java:118)
    	org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
    	org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:925)
    	org.apache.jsp.listclaims_jsp._jspx_meth_c_005fforEach_005f0(listclaims_jsp.java:125)
    	org.apache.jsp.listclaims_jsp._jspService(listclaims_jsp.java:99)
    	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    
    
    root cause 
    
    java.lang.NullPointerException
    	com.webhomecover.dao.ClaimDAO.readClaims(Unknown Source)
    	com.webhomecover.model.ModelFacade.getClaims(Unknown Source)
    	com.webhomecover.beans.ClaimCollection.getClaims(Unknown Source)
    	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	java.lang.reflect.Method.invoke(Method.java:597)
    	javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
    	javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
    	org.apache.el.parser.AstValue.getValue(AstValue.java:118)
    	org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
    	org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:925)
    	org.apache.jsp.listclaims_jsp._jspx_meth_c_005fforEach_005f0(listclaims_jsp.java:125)
    	org.apache.jsp.listclaims_jsp._jspService(listclaims_jsp.java:99)
    	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    Java Code:
      <?xml version="1.0"?>
    <!-- File: listclaims.jsp -->
    
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"	
       xmlns:c="http://java.sun.com/jsp/jstl/core" 		
       version="2.0">
    <jsp:directive.page isELIgnored="false" />
    <jsp:directive.page contentType="text/html"/>   
    <jsp:output omit-xml-declaration="false"
     doctype-root-element="html"
     doctype-public="-//W3C//DTD XHTML 1.1//EN" 
     doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" />
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
     <link href="webhomecover.css" rel="stylesheet" type="text/css" />
     <title>Insurance Claims</title>
    </head>
     <body>
      <p>Here is a list of claims</p>
      <table>
       <tr>
        <th>reference</th><th>description</th><th>amount</th><th>approved</th><th>claimDate</th>
       </tr>
    
       <jsp:useBean id="claimCollection" class="com.webhomecover.beans.ClaimCollection" />
       <c:forEach var="claim" items="${claimCollection.claims}">
        <tr>
         <td><c:out value="${claim.reference}" /></td>
         <td><c:out value="${claim.description}" /></td>
         <td><c:out value="${claim.amount}" /></td>
         <td><c:out value="${claim.approved}" /></td>
         <td><c:out value="${claim.claimDate}" /></td>
        </tr>
       </c:forEach>
      </table>
     </body>
     </html>
    </jsp:root>
    Last edited by lse123; 04-25-2010 at 02:26 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Test the ClaimCollections bean in isolation.
    Does it work?

  3. #3
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default is it faults where clause?

    claims is a list of claim.
    String x=new String(); provides empty string or needed inside parenthesis "" (doublequotes)?

    is it faults where clause?

    Java Code:
    //com.webhomecover.beans.ClaimCollection 
    
      package com.webhomecover.beans;
    
    import java.util.*;
    import com.webhomecover.model.ModelFacade;
    import com.webhomecover.model.Claim;
    
    public class ClaimCollection
    {
     private String whereClause = new String();
    
     public String getWhereClause()
     {
      return whereClause;
     }
     
     public void setWhereClause(String whereClause)
     {
      this.whereClause = whereClause;
     }
    
     public Collection<Claim> getClaims()
     {
      Collection<Claim> claims = ModelFacade.getClaims(whereClause);
      return claims;
     }
    }
    Java Code:
      package com.webhomecover.model;
    
    import com.webhomecover.dao.ClaimDAO;
    import java.util.Collection;
    
    
    public class ModelFacade
    {
     public static Collection<Claim> getClaims(String whereClause)
     {
      // if no 'where' clause string is passed in, create an empty string
      if(whereClause == null)
      {
       whereClause = new String();
      }
      ClaimDAO cdao = new ClaimDAO();
      Collection<Claim> claimCollection = cdao.readClaims(whereClause);
      return claimCollection;
     }
    }
    Java Code:
     //  com.webhomecover.dao.ClaimDAO.java
    .....................
       public Collection<Claim> readClaims(String whereClause)
       {
        Collection<Claim> claims = new ArrayList<Claim>();
        try
        {
         getConnection();
         Statement statement = connection.createStatement();
         ResultSet results = statement.executeQuery("SELECT * FROM claim " + whereClause);
         String reference = null; 
         String description = null;
         double amount = 0.0;
         boolean approved = false;
         java.sql.Date claimDate = null;
         Claim claim = null;
         while(results.next())
         {
          reference = results.getString("reference"); 
     	  description = results.getString("description");
     	  amount = results.getDouble("amount");
     	  approved = results.getBoolean("approved");
     	  claimDate = results.getDate("claimDate");
     	  claim = new Claim();
     	  claim.setReference(reference);
     	  claim.setDescription(description);
     	  claim.setAmount(amount);
     	  claim.setApproved(approved);
     	  claim.setClaimDate(claimDate);
     	  claims.add(claim);
         }
         results.close();
         results = null;
         statement.close();
         statement = null;
         connection.close();
         connection = null;
        } 
        catch(SQLException e)
        {
         e.printStackTrace();
        }
        finally
        {
         cleanUp();
        }
        return claims;
       }  .....................

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Does that work in isolation, though?
    If not, then where is it going wrong?

  5. #5
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    by saying isolation you mean get out off app?

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Yes.
    That's how you test things.
    Run them by themselves, especially stuff interacting with a database.
    Otherwise how do you know if what you've written actually works?

  7. #7
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    there is another file in app:
    go and run it?
    pools exist and in desktop app connections (from 4 types of db conn which pools permited?) ?

    Java Code:
    // ClaimDAOTest.java
    package com.webhomecover.tests;
    
    import java.sql.*;
    import java.util.*;
    
    import com.webhomecover.dao.*;
    import com.webhomecover.model.*;
    
    public class ClaimDAOTest
    {
     public static void main(String[] args)
     {
       ClaimDAO cdao = new ClaimDAO();
       Collection<Claim> c = cdao.readClaims("");
       Iterator<Claim> iter = c.iterator();
       System.out.println("id\tdescription\tamount\tapproved\tclaimDate");
       while(iter.hasNext())
       {
        Claim claim = iter.next();
        System.out.println(claim.getReference() + "\t" + claim.getDescription() + "\t" + claim.getAmount() + "\t" + claim.getApproved() + "\t" + claim.getClaimDate());
      }
     }
    }

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Does that work?

  9. #9
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    since the main app is web app and this not(ClaimDAOTest.java), how to run? requires running web server to run it? I use db conn pools...

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    I have no idea what this needs to run...it's your code!

    If you have connection pools I'm sure, if you've written the code suitably openly, you should be able to dummy the connection stuff. Even if it's something as basic as redoing getConnection() to simply build a connection and not use a pool.

    You're trying to see if this code works.

    By the way, looking at your stuff again...doing SQL in a for loop like that is not a good idea. Go through a servlet which gets the arraylist and passes it to the JSP in the request. I'm can't guarantee it, but I would think the current way you have things here might hit the db everytime it loops. Depends how the for-each works.

  11. #11
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    I will test code tomorrow, but since, this is a textbook example inside the text, must be correct, any tip about this for the code(additional)?

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    I wouldn't bet on it being correct.

    But, as I said, that SQL query in a for-each simply looks wrong.
    The usual technique is to have a servlet (and business layer and db layer) get the data for the JSP to display.

  13. #13
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    you may find the complete app I refer at

    Cengage Learning -Dynamic Web Application Development

    Examples:Chapter 12: 12-3 folder [database in 12-1]

    I am currently debugging...

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    If they're suggesting you do your for-each like that, with essentially a DAO supplying the results directly, then I would suggest looking for a different course to work through.

  15. #15
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    I'm late here but the trace says you have a nullpointer in your readClaims method.
    In that method you do
    Java Code:
         results.close();
         results = null;
         statement.close();
         statement = null;
         connection.close();
         connection = null;
    then in the finally you call a method called cleanUp. What does that cleanUp method do?

  16. #16
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    This was why I was trying to get them to actually test the database gubbins in isolation.

  17. #17
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    The role of this method is to attempt to close any resourses that may have been left open by exceptions being thrown...

    can you download and try code from textbook site above, must be correct?

  18. #18
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    If that's the way they've written their code then I would question the quality of the course.
    They are not closing resources in a finally block (ie resultset and statement).

    I'm not going to grabn code and try it out...since you're doing the course you need to figure out whether what you have matches the course code. If it doesn't then there's your problem.

  19. #19
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    Using db conn pools,
    .........
    private static final String DATASOURCE_NAME = "java:comp/env/jdbc/webhomecoverds";
    .........
    this[vars] must unique among ALL Tomcat's Web Apps (localhost)? or not required...?

  20. #20
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    // ClaimDAOTest.java in #7

    must run from C:\JSPAdv\webhomecover\WEB-INF\classes

    WHAT CLI COMMAND TO USE?
    Last edited by lse123; 04-30-2010 at 01:51 PM.

Page 1 of 2 12 LastLast

Similar Threads

  1. JavaBean
    By hannes in forum New To Java
    Replies: 5
    Last Post: 02-14-2010, 08:51 PM
  2. components in javabean
    By NAIYYAR ALI in forum Advanced Java
    Replies: 0
    Last Post: 10-05-2009, 04:36 PM
  3. Debug challenge: how do you debug a Java program?
    By CJSLMAN in forum New To Java
    Replies: 60
    Last Post: 07-04-2009, 11:28 AM
  4. Enterprise JavaBean 3.0
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 06-20-2008, 12:42 AM
  5. JavaBean Problem
    By Peter in forum Advanced Java
    Replies: 2
    Last Post: 07-05-2007, 02:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •