Solved

Urgent Help needed with for loop in Beans(should be simple)

Posted on 2004-09-03
17
274 Views
Last Modified: 2010-04-01
Hello
I have two beans: BookingBean and DBAccess bean
BookingBean retrieves data from a jsp form and validates it
then the DBAccess bean performs all the database updates and inserts etc.

the problem is that i had the BookingBean set up to get only one value for the bookingsNo value from the JSP even though it sends more than one furthermore the DBAccess method for writing this to the DB only writes one value, I guess i need a for loop or two and am not sure where to put them in the beans
i have included the code for the above ...please please help!!

Code to get this value in BookingBean
//sets and gets the bookingNo
  public String getBookingsNo()
  {
   
    System.out.println( "getBookingsNo got this: " + bookingsNo ) ;
    return bookingsNo ;
  }

  public void setBookingsNo( String bookingsNo )
  {
    this.bookingsNo = bookingsNo ;
    System.out.println( "setBookingsNo got this: " + bookingsNo ) ;
  }


>>>>>>>JSP
<%
  Connection conn = null;
  PreparedStatement p = null;// pulls data for booking from SearchRes.jsp using booking number
  //Result set
  ResultSet rs = null;
  try
  {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    conn = DriverManager.getConnection("jdbc:odbc:BillBoardCompany");
    p = conn.prepareStatement("SELECT SiteBookings.BookingsNo, SiteBookings.SiteID, SiteInformation.SiteLocation, SiteBookings.CycleID, SiteBookings.BookYear FROM SiteInformation INNER JOIN (CycleInformation INNER JOIN SiteBookings ON CycleInformation.CycleID = SiteBookings.CycleID) ON SiteInformation.SiteID = SiteBookings.SiteID WHERE SiteBookings.BookingsNo = ?" );
    String booknos[] = request.getParameterValues("bookingsNo");
   
%>

 <%
       for( int ii=0; booknos!=null && ii<booknos.length; ii++ )
    {
      int bookno = Integer.parseInt( booknos[ii] );
      p.setInt(1,bookno);

      // pass bookno to the bean for further processin
      // run query p
      rs = p.executeQuery();
        
        while (rs.next())
      {
%>
    <tr bgcolor="#FFFFFF">
     
      <td height="10"><div align="center"><%= rs.getString("BookingsNo") %></div></td>
      <td height="10"><div align="center"><%= rs.getString("SiteID") %></div></td>
      <td height="10"><div align="center"><%= rs.getString("SiteLocation") %></div></td>
      <td height="10"><div align="center"><%= rs.getString("CycleID") %></div></td>
       <td height="10"><div align="center"><%= rs.getString("BookYear") %></div></td>...

  <%
       }// end the while loop
        
%>  
</table>

<%
   }// end for loop
  } // try
  catch (Exception e)
  {
    out.print("Exception: " + e);
    e.printStackTrace();
  }
  finally
  {
    if( rs != null ) try { rs.close(); } catch( Throwable t ) { t.printStackTrace(); }
    if( conn != null ) try { conn.close(); } catch( Throwable t ) { t.printStackTrace(); }
  }
%>


>>>>DBAccess bean
public boolean insertSitebook( BookingBean bean )
  {
    Connection conn = null ;
    PreparedStatement z = null ;
    try
    {
      Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
      conn = DriverManager.getConnection( "jdbc:odbc:BillboardCompany" ) ;
      z = conn.prepareStatement( "UPDATE SiteBookings SET CustomerID = ?, CampaignRef = ?, Price = ?, BookDate = ? WHERE BookingsNo = ? " ) ;

      z.setString( 1, bean.getCustId() ) ;
      z.setString( 2, bean.getCampRef() ) ;
      z.setString( 3, bean.getPriceNum() ) ;
      z.setTimestamp( 4, new java.sql.Timestamp( new java.util.Date().getTime() ) ) ;
      z.setString( 5, bean.getBookingsNo() ) ; /////////////////////////////////////////////// this is the value that needs the for loop i think?
      z.executeUpdate() ;
      return true ;
    }
    catch( ClassNotFoundException ex )
    {
      ex.printStackTrace();
      return false ;
    }
    catch( SQLException ex )
    {
      ex.printStackTrace();
      return false ;
    }
    finally
    {
      try { if( z != null ) z.close() ; } catch( SQLException ex ) {}
      try { if( conn != null ) conn.close() ; } catch( SQLException ex ) {}
    }
  }
   
0
Comment
Question by:Gar04
  • 11
  • 2
  • 2
17 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 11971987
Hi Gar ;-)

Just a quick note, you need to change:

  finally
  {
    if( rs != null ) try { rs.close(); } catch( Throwable t ) { t.printStackTrace(); }
    if( conn != null ) try { conn.close(); } catch( Throwable t ) { t.printStackTrace(); }
  }

to

  finally
  {
    if( rs != null ) try { rs.close(); } catch( Throwable t ) { t.printStackTrace(); }
    if( p != null ) try { p.close(); } catch( Throwable t ) { t.printStackTrace(); }
    if( conn != null ) try { conn.close(); } catch( Throwable t ) { t.printStackTrace(); }
  }

To make sure the PreparedStatement is closed too ;-)

Can you explain what your problem is a bit more?  I'm not sure I can see what's wrong/missing from the bit you posted...
0
 

Author Comment

by:Gar04
ID: 11971998
i am pretty desperate to get this working and am in a muddle
any help would be excellent
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11972014
That jsp you posted doesn't call DBAccess at all at the moment...

And it looks like a display page you posted, not a page for setting values back into the database...

Did you post the right bit of code?
0
 

Author Comment

by:Gar04
ID: 11972066
cheers for the reply tim
when you helped me with this before i forgot to ask you how to
ensure that multiple bookings can be made
instead of just one at a time
if you look at the above code for the JSP
you will see that it has a for loop for multiple values for the bookingsNo
in the JSP the bean is set up to get this data
<jsp:useBean id="Bean5" class="com.ora.jsp.beans.codes.BookingBean" scope="session"/>
<jsp:setProperty name="Bean5" property="*"/>
however, i think that the BookingBean needs a for loop in its get and set methods to
get all the values if there are more than one
then i think that the DBAccess bean needs a for loop to update all the booking info to the DB
where BookingsNo = all the bookingsNo values

i hope this makes sense
i tested it this morning and it only inserts one booking even if more than one is selected

If you wan i can send you all the code?
0
 

Author Comment

by:Gar04
ID: 11972111
i thought i did hang on....

sorry i only sent a little bit of the JSP here it all is

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" %>
<jsp:useBean id="Bean5" class="com.ora.jsp.beans.codes.BookingBean" scope="session"/>
<jsp:useBean id="Bean6" class="com.ora.jsp.beans.codes.DBAccess" scope="session"/>
<jsp:setProperty name="Bean5" property="*"/>
<%
    if( Bean5.isValid() )
    {
       Bean6.retrieveData( Bean5 );
        
    }
%>
<%@ page import="java.io.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>BookingPage</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  </head>
  <body>
<%
  Connection conn = null;
  PreparedStatement p = null;// pulls data for booking from SearchRes.jsp using booking number
  //Result set
  ResultSet rs = null;
  try
  {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    conn = DriverManager.getConnection("jdbc:odbc:BillBoardCompany");
    p = conn.prepareStatement("SELECT SiteBookings.BookingsNo, SiteBookings.SiteID, SiteInformation.SiteLocation, SiteBookings.CycleID, SiteBookings.BookYear FROM SiteInformation INNER JOIN (CycleInformation INNER JOIN SiteBookings ON CycleInformation.CycleID = SiteBookings.CycleID) ON SiteInformation.SiteID = SiteBookings.SiteID WHERE SiteBookings.BookingsNo = ?" );
    String booknos[] = request.getParameterValues("bookingsNo");
   
%>
<div align="center"></div>
<tr>
       
   
      <div align="left"></div>
          <div align="right"></div>
          <div align="right"></div>
                 
       
  <table width="100%" height="69" border="1" cellpadding="0" cellspacing="0" bordercolor="#3399CC">
    <tr>
      <td width="10%" bgcolor="#336699"><div align="center"><font color="#FFFFFF" size="1">Booking
          No.</font></div></td>
      <td width="10%" bgcolor="#336699"><div align="center"><font color="#FFFFFF" size="1">Site
          ID</font></div></td>
      <td width="50%" bgcolor="#336699"><div align="center"><font color="#FFFFFF" size="1">Site
          Location </font></div></td>
      <td width="15%" bgcolor="#336699"><div align="center"><font color="#FFFFFF" size="1">Cycle
          ID </font></div></td>
      <td width="15%" bgcolor="#336699"><div align="center"><font color="#FFFFFF" size="1">Book
          Year </font> </div>
        <div align="center"></div></td>
    </tr>
    <%
       for( int ii=0; booknos!=null && ii<booknos.length; ii++ )
    {
      int bookno = Integer.parseInt( booknos[ii] );
      p.setInt(1,bookno);

      // pass bookno to the bean for further processin
      // run query p
      rs = p.executeQuery();
        
        while (rs.next())
      {
%>
    <tr bgcolor="#FFFFFF">
     
      <td height="10"><div align="center"><%= rs.getString("BookingsNo") %></div></td>
      <td height="10"><div align="center"><%= rs.getString("SiteID") %></div></td>
      <td height="10"><div align="center"><%= rs.getString("SiteLocation") %></div></td>
      <td height="10"><div align="center"><%= rs.getString("CycleID") %></div></td>
       <td height="10"><div align="center"><%= rs.getString("BookYear") %></div></td>
   
    </tr>
      
    <tr bgcolor="#336699">
      <td height="10" colspan="8"> <div align="center"> </div>
        <div align="center"></div>
        <div align="center"></div>
        <div align="center"></div>
        <div align="center"></div>
        <div align="center"> <font color="#FFFFFF" size="1"> Please enter the
          relevant Customer Information below. </font> </div>
        <div align="center"></div>
        <div align="center"></div>
        <div align="center"></div>
        <div align="center"></div>
        <div align="center"> </div>
        <div align="center"></div>
        <div align="center"></div>
        <div align="center"></div>
        <div align="center"> <font color="#FFOOOO"> </font> </div>
        <div align="center"> </div></td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td colspan="8"> <div align="center">
          <%-- List All Invalid Data, If Any!--%>
          <font color="#FF0000">
          <jsp:getProperty name="Bean5" property="propertyStatusMsg"/>
          </font>
          <%-- Continue List --%>
        </div></td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td colspan="8"><div align="center"><% String[] details= Bean5.getPropertyStatusDetails();
                                     for(int j=0; j<details.length;j++) {
                                   out.print("<li>"+ details[j] +"</li>");
                                   }
                  %> </div></td>
    </tr>
    <tr bgcolor="#336699">
      <td height="20" colspan="8">&nbsp;</td>
    </tr>
 
        <%
       }
        
%>  
</table>

<%
   }// end for loop
  } // try
  catch (Exception e)
  {
    out.print("Exception: " + e);
    e.printStackTrace();
  }
  finally
  {
    if( rs != null ) try { rs.close(); } catch( Throwable t ) { t.printStackTrace(); }
    if( p != null ) try { p.close(); } catch( Throwable t ) { t.printStackTrace(); }
    if( conn != null ) try { conn.close(); } catch( Throwable t ) { t.printStackTrace(); }
  }

%>
  </body>
</html>
0
 

Author Comment

by:Gar04
ID: 11972166
Tim i also think that the for loop in the JSP is ended in the wrong place cos i now get a null pointer exception
0
 

Author Comment

by:Gar04
ID: 11972247
Tim this is the page that
sends the data to the BookingPage and by association the Beans

SearchRes.jsp
>>>>>>>>>>>

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" %>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = null;
CallableStatement cs = null;
try
{
  conn = DriverManager.getConnection("jdbc:odbc:BillBoardCompany");
  cs = conn.prepareCall("{Call SiteSearchQ(?, ?, ?)}");
 
  String snames[] = request.getParameterValues("SiteName");
  %>
     
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SearchRes</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">



</head>
<body>
<form name=Bookform Action="BookingPage.jsp" method="post">
  <table width="95%" border="1" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
    <!--DWLayoutTable-->
    <tr>
      <td height="74" colspan="4" align="left" valign="bottom" bgcolor="#FFFFFF">
        <div align="right"></div>
        <div align="left"></div>
        <div align="left"></div>
        <table width="99%" height="34" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#006699">
          <tr bordercolor="#0033CC">
            <td width="245" height="20" align="center" valign="middle"> <div align="center"></div>
              <strong><font color="#000000" size="1">&nbsp;</font></strong><font color="#000000" size="1"><strong>Site
              Location</strong></font></td>
            <td width="155" height="20" align="center" valign="middle"> <div align="center"><font color="#000000" size="1"><strong>Site
                Format</strong></font></div></td>
            <td width="83" align="center" valign="middle"> <font color="#000000" size="1">&nbsp;<strong>Prismatic</strong></font></td>
            <td width="72" align="center" valign="middle" bgcolor="#FFFFFF"> <div align="center"><font color="#000000" size="1"><strong>Illuminated</strong></font></div></td>
            <td width="67" align="center" valign="middle"> <div align="center"><font color="#000000" size="1"><strong>CycleStart</strong></font></div></td>
            <td width="119" align="center" valign="middle"> <div align="center"><font color="#000000" size="1"></font></div>
              <div align="center"></div>
              <div align="center"><font color="#000000" size="1"><strong>CycleEnd</strong></font></div></td>
            <td colspan="2" align="center" valign="middle"> <div align="center">
                <div align="center"><font color="#000000" size="1"></font></div>
                <div align="center"><font size="1"><strong>Book</strong></font></div>
                <font color="#000000" size="1"></font></div>
              <div align="center"></div></td>
          </tr>
<%
    for( int ii=0; snames!=null && ii<snames.length; ii++ )
    {
      String siteName = snames[ii];
     
      int selCyc=Integer.parseInt( request.getParameter("SelectCyc"));
      int year=Integer.parseInt( request.getParameter("SelectYear"));
 
     
      cs.setString(1,siteName);
      cs.setInt(2, selCyc );
      cs.setInt(3, year);
   
      ResultSet rs = cs.executeQuery();
      while (rs.next())
      {
%>
          <tr bgcolor='#EEEFF3' onMouseOver="this.bgColor='#B2C4F0';" onMouseOut="this.bgColor='#EEEFF3';">
            <input name="siteId" type="hidden" value="<%=rs.getString("SiteID")%>">
            <td height="12"> <div align="center"></div>
              <div align="center"></div>
              <div align="center"><font color="#000000" size="1"><%=rs.getString("SiteLocation")%></font></div></td>
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString("SiteType")%></font></div></td>
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString ("Prismatic")%></font></div></td>
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString ("Illuminated")%></font></div></td>
            <input name="cycleId" type="hidden" value="<%=rs.getString("CycleID")%>">
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString ("CycleStart")%></font></div></td>
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString ("CycleEnd")%></font></div></td>
            <input name="bookYear" type="hidden" value="<%=rs.getString("BookYear")%>">
            <td width="120"><div align="center"><font color="#000000" size="1">
                <input type="checkbox" name="bookingsNo" value="<%=rs.getString("BookingsNo")%>">
                </font></div></td>
          </tr>
<%
        } // end the while loop
    }// end the for loop
%>
        </table>
        <div align="center"> </div></td>
    </tr>
    <tr valign="middle">
      <td colspan="4" align="center" bgcolor="#FFFFFF"></td>
    </tr>
    <tr valign="middle">
      <td height="21" colspan="4" align="center" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Company Name</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="compName" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Company Address</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="compAddress" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">City </font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="cityName" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Country</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="countryName" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Postcode</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="postCode" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Phone Number</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="phoneNum" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Fax Number</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="faxNum" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Email Address</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="emailAdd" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Product Name</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="prodName" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Product Category</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="prodCat" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Price</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="priceNum" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
      <td align="center" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
    </tr>
    <tr valign="middle">
      <td colspan="4" align="center" bgcolor="#FFFFFF"><input type=submit name=Submit value="BookIt"></td>
    </tr>
  </table>
</form>
<%
}
    catch (Exception e)
    {
     e.printStackTrace() ;
     out.print("Exception: " + e);
       

    }
    finally
    {
     if( cs != null ) try { cs.close(); } catch( Throwable t ) { t.printStackTrace(); }
     if( conn != null ) try { conn.close(); } catch( Throwable t ) { t.printStackTrace(); }
    }
%>
</body>
</html>
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Gar04
ID: 11972340
right i got rid of the null pointer exception
i still can't get the methods in the beans to update more than one booking at a time
have you any ideas at all tim
i really could be doing with you expert advice
i guess i need an array but i am just figuring out how to use 'em and can't get it workin'

gaz
0
 

Author Comment

by:Gar04
ID: 11972390
pLease let me know if you can help Tim
i am running out of time
Gaz
;)
0
 

Author Comment

by:Gar04
ID: 11972527
this is the part of the BookingBean
that graps the bookingsNo value (it should be values)

//BookingBean.java
//==============

package com.ora.jsp.beans.codes;

import java.util.ArrayList ;

/**
 * bean used to capture booking data, validate it and write it to Database.
 */
public class BookingBean
{
  // Bean Properties
  private String compName ;
  private String compAddress ;
  private String cityName ;
  private String countryName ;
  private String postCode ;
  private String phoneNum ;
  private String faxNum ;
  private String emailAdd ;
  private String prodName ;
  private String prodCat ;
  private String priceNum ;

  private String bookingsNo ;
  private String siteId ;
  private String cycleId ;
  private String bookYear ;

  private String custId ;
  private String campRef ;

  private boolean isInitialized ; // to ensure the form is initialized

  // SET and GET methods for all the Variables
  //sets and gets the compName property value
  public String getCompName()
  {
    return compName ;
        }

  public void setCompName( String compName )
  {
    isInitialized = true ;
    this.compName = compName ;
        }
...
 //sets and gets the bookingNo
  public String getBookingsNo()
  {
   
    System.out.println( "getBookingsNo got this: " + bookingsNo ) ;
    return bookingsNo ;
  }

  public void setBookingsNo( String bookingsNo )
  {
    this.bookingsNo = bookingsNo ;
    System.out.println( "setBookingsNo got this: " + bookingsNo ) ;
  }


i think that i need an array here instead
can you please help cos i am lost

 
0
 

Author Comment

by:Gar04
ID: 11972729
Hey Tim
I cannot stress how much i need your help with this
one
I need arrays to make multiple bookings but i can't figure out where and how to do them
i have a book and it sucks
gaz
0
 
LVL 11

Accepted Solution

by:
sompol_kiatkamolchai earned 500 total points
ID: 11978920
OK. After reading quite long conversion of you and Tim, I think your problem is how to have and manage array type in javabean.

You need to change data type of bookingsNo from String to String[]

  private String[] bookingsNo ;

  public String[] getBookingsNo()
  {
   
    System.out.println( "getBookingsNo got this: " + bookingsNo ) ;
    return bookingsNo ;
  }

  public void setBookingsNo( String[] bookingsNo )
  {
    this.bookingsNo = bookingsNo ;
    System.out.println( "setBookingsNo got this: " + bookingsNo ) ;
  }


and then you can use
<jsp:setProperty name="Bean5" property="*"/> or
<jsp:setProperty name="Bean5" property="bookingsNo"/>

to set data to javabean. Servlet Container will automatically set data to array type
if you have a request like this

http://localhost:8080/someContext/test.jsp?bookingsNo=Book1&bookingsNo=Book2

so when you call Bean5.getBookingsNo() it will return array of String
{"Book1","Book2"}

To access array data from javabean you cannot use
<jsp:getProperty name="Bean5" property="bookingsNo"/>
since it will return something like this
String[]@0xsdfssdsds

So you should use this

<%
String[] bookingsNo = Bean5.getBookingsNo();
if(bookingsNo != null) {
  for ( int i=0; i<bookingsNo.length; i++) {
%>
  Bookings No is = <%=bookingsNo[i]%>
<%
  }
}
%>

Hope this help.
0
 

Author Comment

by:Gar04
ID: 11979466
cheers sompol,
 how do i then get the values of bookingsNo for the following method, do i need the for loop there?
 marked with * below:

public boolean insertSitebook( BookingBean bean )
  {
    Connection conn = null ;
    PreparedStatement z = null ;
    try
    {
      Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
      conn = DriverManager.getConnection( "jdbc:odbc:BillboardCompany" ) ;
      z = conn.prepareStatement( "UPDATE SiteBookings SET CustomerID = ?, CampaignRef = ?, Price = ?, BookDate = ? WHERE BookingsNo = ? " ) ;

      z.setString( 1, bean.getCustId() ) ;
      z.setString( 2, bean.getCampRef() ) ;
      z.setString( 3, bean.getPriceNum() ) ;
      z.setTimestamp( 4, new java.sql.Timestamp( new java.util.Date().getTime() ) ) ;
     ***************************************
      z.setString( 5, bean.getBookingsNo() ) ;                   *
      **************************************
     z.executeUpdate() ;
      return true ;
    }
    catch( ClassNotFoundException ex )
    {
      ex.printStackTrace();
      return false ;
    }
    catch( SQLException ex )
    {
      ex.printStackTrace();
      return false ;
    }
    finally
    {
      try { if( z != null ) z.close() ; } catch( SQLException ex ) {}
      try { if( conn != null ) conn.close() ; } catch( SQLException ex ) {}
    }
  }
0
 

Author Comment

by:Gar04
ID: 11979521
i have tried testin this
and i get a NullpointerException
i tried this in the method
of the DBAccess bean
public boolean insertSitebook( BookingBean bean )
  {
    Connection conn = null ;
    PreparedStatement z = null ;
    try
    {
      Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
      conn = DriverManager.getConnection( "jdbc:odbc:BillboardCompany" ) ;
      z = conn.prepareStatement( "UPDATE SiteBookings SET CustomerID = ?, CampaignRef = ?, Price = ?, BookDate = ? WHERE BookingsNo = ? " ) ;

      z.setString( 1, bean.getCustId() ) ;
      z.setString( 2, bean.getCampRef() ) ;
      z.setString( 3, bean.getPriceNum() ) ;
      z.setTimestamp( 4, new java.sql.Timestamp( new java.util.Date().getTime() ) ) ;
      //z.setString( 5, bean.getBookingsNo() ) ;
      String[] bookNos = bean.getBookingsNo();
            if(bookNos != null) {
              for ( int i=0; i<bookNos.length; i++) {
            z.setString(5, bookNos[i]);

                    }
            }

0
 
LVL 11

Expert Comment

by:sompol_kiatkamolchai
ID: 11983053
Please check the name of variable in javabean. It should exactly match with the name of HTML element name.
If you're still having problem, please dump your current source code.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Hyena v12.2 is now available for downloading and is available in English, French, German and Spanish versions.
Use of TCL script on Cisco devices:  - create file and merge it with running configuration to apply configuration changes
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now