Update functionality

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mohammed Mazid

    Update functionality

    Hi guys,

    I was trying to program an application that would be used to update
    the flight. Basically using a JSP form I am updating a flight and its
    associated details. However, it does not do it as it cannot pass the
    flightNo parameter. Therefore can anyone please suggest correction to
    that please and add in a code that would work efficiently?

    Here is the code snippet:

    class FlightDAO
    {
    void update(Flight flight)
    {
    //Assume already statements there

    // Create the UPDATE update_stmt
    PreparedStateme nt update_stmt = null;

    try
    {
    // Get a database connection
    connection = connectionPool. getConnectionNo Wait();

    // Create SQL UPDATE statement
    update_stmt = connection.prep areStatement(UP DATE_STMT);
    update_stmt.set Date(2, flight.flightDa te);
    update_stmt.set String(3, flight.destinat ion);
    update_stmt.set Time(4, flight.arrTime) ;
    update_stmt.set Time(5, flight.depTime) ;

    // Perform the SQL UPDATE
    update_stmt.exe cuteUpdate();

    // Handle any SQL errors
    }
    catch (SQLException se)
    {
    //Assume some catch statements
    }

    private static final String UPDATE_STMT
    = "UPDATE Flight"
    + "SET FlightDate = ?, Destination = ?, ArrivalTime = ?,
    DepartureTime = ?"
    + "WHERE FlightNo = ?";
    }

    public class FlightService
    {
    private FlightDAO flightDataAcces s;

    public FlightService()
    {
    flightDataAcces s = new FlightDAO();
    }

    public Flight updateFlight(St ring flightNo, Date flightDate, String
    destination,
    Time depTime, Time arrTime)
    {
    // Create the Flight object
    Flight flight = new Flight(flightNo , flightDate, destination,
    arrTime, depTime);

    // Perform the DB transaction
    flightDataAcces s.update(flight );

    return flight;
    }

    It is not the whole program, just part of the source code is shown.
    Can anyone please show me how to pass the flightNo parameter and also
    correction of the update function so that it would work in the
    database?

    I think there is no need to show ConnectionPool source code and so on.
    There is only update and the passing of the flightNo parameter
    correction is required.

    Much appreciated.
  • SteveE

    #2
    Re: Update functionality

    >[color=blue]
    > private static final String UPDATE_STMT
    > = "UPDATE Flight"
    > + "SET FlightDate = ?, Destination = ?, ArrivalTime = ?,
    > DepartureTime = ?"
    > + "WHERE FlightNo = ?";[/color]

    Check your update statement. As it stands, it reads:

    "UPDATE FlightSET FlightDate = ?, Destination = ?, ArrivalTime = ?,
    DepartureTime = ?WHERE FlightNo = ?"

    You need a couple of spaces in there.

    Cheers,
    Steve.

    Comment

    • Ryan Stewart

      #3
      Re: Update functionality

      "Mohammed Mazid" <kadmazid@hotma il.com> wrote in message
      news:7cfd7b4a.0 403270214.14b4a b2@posting.goog le.com...
      *snip*[color=blue]
      > update_stmt = connection.prep areStatement(UP DATE_STMT);
      > update_stmt.set Date(2, flight.flightDa te);
      > update_stmt.set String(3, flight.destinat ion);
      > update_stmt.set Time(4, flight.arrTime) ;
      > update_stmt.set Time(5, flight.depTime) ;[/color]
      *snip*[color=blue]
      > private static final String UPDATE_STMT
      > = "UPDATE Flight"
      > + "SET FlightDate = ?, Destination = ?, ArrivalTime = ?,
      > DepartureTime = ?"
      > + "WHERE FlightNo = ?";[/color]
      *snip*
      Aside from the problem pointed out by SteveE, your set statements are all
      wrong. Flight date is not the second argument, and you never set a first.


      Comment

      • Ryan Stewart

        #4
        Re: Update functionality

        "Ryan Stewart" <zzanNOtozz@gSP AMo.com> wrote in message
        news:y-qdnepJmJbqBPjd4 p2dnA@texas.net ...[color=blue]
        > "Mohammed Mazid" <kadmazid@hotma il.com> wrote in message
        > news:7cfd7b4a.0 403270214.14b4a b2@posting.goog le.com...
        > *snip*[color=green]
        > > update_stmt = connection.prep areStatement(UP DATE_STMT);
        > > update_stmt.set Date(2, flight.flightDa te);
        > > update_stmt.set String(3, flight.destinat ion);
        > > update_stmt.set Time(4, flight.arrTime) ;
        > > update_stmt.set Time(5, flight.depTime) ;[/color]
        > *snip*[color=green]
        > > private static final String UPDATE_STMT
        > > = "UPDATE Flight"
        > > + "SET FlightDate = ?, Destination = ?, ArrivalTime = ?,
        > > DepartureTime = ?"
        > > + "WHERE FlightNo = ?";[/color]
        > *snip*
        > Aside from the problem pointed out by SteveE, your set statements are all
        > wrong. Flight date is not the second argument, and you never set a first.
        >[/color]
        Oh, and if you want answers, post to comp.lang.java. help or
        comp.lang.java. programmer in the future. The former is for beginners. The
        latters is for more advanced topics. This group is not carried by all
        servers.


        Comment

        Working...