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

    Default can you tell how transfer a List eg. created as...between files jsp/java

    well can you tell how transfer a List eg. created as
    Java Code:
       public List getLineList() {  // this in file beans.OrderTotals
         return lineList;
       }
    
        public static void addPlant(OrderPlantItem orderPlantItem) {    //  OrderPlantItem  is a DTO bean
    
                lineList.add( orderPlantItem );
        }
    from bean to jsp or from bean to bean or from jsp call to bean, and appear contents on screen or populate a Table(db) ?

    Java Code:
    //this in file beans.AddOrder
    ........
    public String updateTables(OrderTotals OrderTotals2, List lineList2) {  // void
         String sqlCommand1= "INSERT INTO Customers VALUES('0011','"+this.getCustName()+"','"+this.getCustStreet()+"','"+this.getCustCity()+"','"+this.getCustState()+"','"+this.getCustZip()+"','2')" ;
         String sqlCommand2= "INSERT INTO Orders VALUES('1011','0011','"+new java.util.Date()+"','"+new java.util.Date()+"',"+OrderTotals2.getTotal()+","+OrderTotals2.getShipping()+","+OrderTotals2.getTax()+")" ;
         String url = "jdbc:odbc:plants"; //dsn plants
         String user="";
         String password="";
         try {
           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
           conn=DriverManager.getConnection
             ("jdbc:odbc:plants", user, password);
           sttmnt=conn.createStatement();
           sttmnt1=conn.createStatement();
           sttmnt2=conn.createStatement();
              //get statement object
          }catch (Exception exception)  {
       //return (exception.getMessage());
          } // end of catch
            finally {
                //
            }
    
          try {
     sttmnt.executeUpdate(sqlCommand1);
     
    
    //Object[] lineList2 = lineList5.toArray();
    
            for (int i = 0; i < lineList2.size(); i++)  //lineList2.length
            {
              OrderPlantItem lineItem0 = (OrderPlantItem)lineList2.get(i);
    
              String sqlCommand3= "INSERT INTO OrderDetail VALUES('1011',"+i+1+","+lineItem0.getPlantID()+","+lineItem0.getQty()+","+lineItem0.getSubtotal()+")" ;
      
                sttmnt2.executeUpdate(sqlCommand3);
            }
                 sttmnt1.executeUpdate(sqlCommand2);
     } // end of try
     catch
    Java Code:
    <jsp:useBean id="add" scope="session" class="beans.AddOrder" />
    <jsp:useBean id="AddChoosePlant" scope="session" class="beans.OrderTotals" />
    
    <% // this code part in file confirm shopping purcase confirm.jsp
    add.updateTables(AddChoosePlant,AddChoosePlant.getLineList());  
      %>

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    I honestly don't understand the question, however I will say that you need to rework that db code.

    You should be using PreparedStatements, and not Statements...binding in the variables, and not concatenating them.

    You're eating exceptions. You have to at least print the stack trace. I mean, if an exception was thrown you wouldn't have a clue.

    Why is the execute for the statement separate from the creation of the statement? If the creation fails (due to a thrown exception) you don't want to simply plow on and try and execute!

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

    Default

    1)db Q

    in a for body that executes a query like above:
    sttmnt2.executeUpdate(sqlCommand3);
    the
    sttmnt2=conn.createStatement();
    must appear outside loop? is this above correct?

    2)Q:List object data appear in jsp(view) or enter in db-table(model) like cartItems in cart

    When I have a List obj contains cartItems objects (eg shopping cart) already populated in a javabean, and want to appear this data to the next jsp file(view) and then enter them in database table via next confirm.jsp that use a process bean(model), what to do to transfer this List Object?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    1) Use a PreparedStatement. Then prepareStatement() outside the loop, and inside the loop bind (setInt(), setString() etc) and execute. You do not want to be using a Statement in this case.

    2) Store them in the session?

  5. #5
    lse123j is offline Member
    Join Date
    Feb 2010
    Posts
    6
    Rep Power
    0

    Default please note the whole bean.OrderTotals that List built and is in, belongs to a sessio

    please note the whole bean.OrderTotals that List built and is in, belongs to a session but I do NOT know how handle the transfer, mainly the reference of objs(List)?

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    What do you mean "transfer"?
    If it's in the session then it's accessible for any request that is part of the same session.

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

    Default

    If the bean is in scope on the page, you use EL to access it
    e.g ${AddChoosePlant.lineList} to access the list returned by the getLineList method.
    Better load those values in the constructor of the bean though so that your getter is always a one liner. You don't want to keep making unnecessary calls to the database.

  8. #8
    lse123j is offline Member
    Join Date
    Feb 2010
    Posts
    6
    Rep Power
    0

    Default is this call to session bean , obj List ...?

    Can you explain inmore detail? I do not know how to retieve obj, anyway I get error I think is from below:
    is this call to session bean , obj List ...?
    Do you want attach complete code files?

    add.updateTables(AddChoosePlant,AddChoosePlant.get LineList()); // jsp confirm
    >>>

    //process bean

    public String updateTables(OrderTotals OrderTotals2, List lineList2) {
    ....
    sttmnt2=conn.createStatement();
    ....
    for (int i = 0; i < lineList2.size(); i++) //lineList2.length
    {
    OrderPlantItem lineItem0 = (OrderPlantItem)lineList2.get(i);

    String sqlCommand3= "INSERT INTO OrderDetail VALUES('1011',"+i+1+","+lineItem0.getPlantID()+"," +lineItem0.getQty()+","+lineItem0.getSubtotal()+") " ;

    sttmnt2.executeUpdate(sqlCommand3);
    }
    >>>

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    What error?

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

    Default error below...attach files

    error below...attach files
    index.htm->OrderPlantItem.jsp(OrderPlantItem.java)->OrderTotals.jsp(OrderTotals.java)->customerDataInsert.html->confirm.jsp(AddOrder.java)

    Q: in netbeans where found servlets files made from jsp during compilation in case an error prompts me...?

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.NoSuchMethodError: beans.AddOrder.updateTables(Lbeans/OrderTotals;Ljava/util/List;)V
    org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:522)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:398)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:390)

    root cause

    javax.servlet.ServletException: java.lang.NoSuchMethodError: beans.AddOrder.updateTables(Lbeans/OrderTotals;Ljava/util/List;)V
    org.apache.jasper.runtime.PageContextImpl.doHandle PageException(PageContextImpl.java:852)
    org.apache.jasper.runtime.PageContextImpl.handlePa geException(PageContextImpl.java:781)
    org.apache.jsp.confirm_jsp._jspService(confirm_jsp .java:141)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:374)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:390)

    root cause

    java.lang.NoSuchMethodError: beans.AddOrder.updateTables(Lbeans/OrderTotals;Ljava/util/List;)V
    org.apache.jsp.confirm_jsp._jspService(confirm_jsp .java:107)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:374)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:390)

    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.
    Apache Tomcat/6.0.18
    Attached Files Attached Files

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    Seems pretty clear to me. There is no updateTables method in AddOrder.

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

    Default

    but in bean AddOrder.java exist...this that add to database (I also tried appear data in a jsp(view) prior add to db,...(commentted code in OrderTotals.jsp) but failed).

    I think for sure error is in representation of List obj in the other file, how to reference?

    AddOrder.java:
    ......................
    public String updateTables(OrderTotals OrderTotals2, List lineList2) { // void
    String sqlCommand1= "INSERT INTO Customers VALUES('0013','"+this.getCustName()+"','"+this.get CustStreet()+"','"+this.getCustCity()+"','"+this.g etCustState()+"','"+this.getCustZip()+"','2')" ;
    String sqlCommand2= "INSERT INTO Orders VALUES('1013','0013','"+new java.util.Date()+"','"+new java.util.Date()+"',"+OrderTotals2.getTotal()+","+ OrderTotals2.getShipping()+","+OrderTotals2.getTax ()+")" ;
    String url = "jdbc:odbc:plants"; //dsn plants

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    This error:
    NoSuchMethodError: beans.AddOrder.updateTables(Lbeans/OrderTotals;Ljava/util/List;)

    means that that method does not exist.

    That it exists in the code you've posted, does not mean it exists inthe code you're running.

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

    Default not reference well the List (to get obj List of objs from one bean to other)

    please note I use netbeans and this is along other beans...

    well may not reference well the List (to get obj List of objs from one bean to other) ?

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

    Default

    Yes well you can't call a method on bean A using a reference to bean B.
    The id you use in the useBean directive is associated with a bean of the class that you specify as the class attribute only.

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

    Default

    what are the 2-3 correct statements then?

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

    Default

    I also do not used <>, at List<obj> statement, is it required/correct syntax? I will cover Generics[List objs of Java SE] chapter in about one month, may you answer now?

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

    Default

    I don't really understand your latest question.
    Did you understand my last explanation?

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

    Default

    in List<obj> statement in the code, I did not used angle brackets, it will also function?
    If you give the correct statements rather, it will be great, otherwise I will review again your answer and code today or tomorrow since is late 24:00 here, thks! again...

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

    Default

    The angle brackets indicate generics. It's not a must to use them but you will get warnings if you don't use them.

Page 1 of 2 12 LastLast

Similar Threads

  1. how to get the list of war files
    By vijayabaskar in forum Java Servlet
    Replies: 0
    Last Post: 04-03-2009, 08:39 AM
  2. how to list certain files in a given directory in java
    By corpusluteum in forum New To Java
    Replies: 6
    Last Post: 09-24-2008, 12:19 AM
  3. List all the files in the current jar
    By Srikanth_From_Moon in forum New To Java
    Replies: 0
    Last Post: 06-14-2008, 08:42 AM
  4. Replies: 20
    Last Post: 12-17-2007, 03:20 PM
  5. How can I get list of files in a directory
    By karma in forum New To Java
    Replies: 2
    Last Post: 12-14-2007, 11:20 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
  •