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
PreparedStatement update_stmt = null;
try
{
// Get a database connection
connection = connectionPool.getConnectionNoWait();
// Create SQL UPDATE statement
update_stmt = connection.prepareStatement(UPDATE_STMT);
update_stmt.setDate(2, flight.flightDate);
update_stmt.setString(3, flight.destination);
update_stmt.setTime(4, flight.arrTime);
update_stmt.setTime(5, flight.depTime);
// Perform the SQL UPDATE
update_stmt.executeUpdate();
// 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 flightDataAccess;
public FlightService()
{
flightDataAccess = new FlightDAO();
}
public Flight updateFlight(String 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
flightDataAccess.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. 3 1591
> private static final String UPDATE_STMT = "UPDATE Flight" + "SET FlightDate = ?, Destination = ?, ArrivalTime = ?, DepartureTime = ?" + "WHERE FlightNo = ?";
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.
"Mohammed Mazid" <ka******@hotmail.com> wrote in message
news:7c*************************@posting.google.co m...
*snip* update_stmt = connection.prepareStatement(UPDATE_STMT); update_stmt.setDate(2, flight.flightDate); update_stmt.setString(3, flight.destination); update_stmt.setTime(4, flight.arrTime); update_stmt.setTime(5, flight.depTime);
*snip* private static final String UPDATE_STMT = "UPDATE Flight" + "SET FlightDate = ?, Destination = ?, ArrivalTime = ?, DepartureTime = ?" + "WHERE FlightNo = ?";
*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.
"Ryan Stewart" <zz********@gSPAMo.com> wrote in message
news:y-********************@texas.net... "Mohammed Mazid" <ka******@hotmail.com> wrote in message news:7c*************************@posting.google.co m... *snip* update_stmt = connection.prepareStatement(UPDATE_STMT); update_stmt.setDate(2, flight.flightDate); update_stmt.setString(3, flight.destination); update_stmt.setTime(4, flight.arrTime); update_stmt.setTime(5, flight.depTime); *snip* private static final String UPDATE_STMT = "UPDATE Flight" + "SET FlightDate = ?, Destination = ?, ArrivalTime = ?, DepartureTime = ?" + "WHERE FlightNo = ?"; *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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Nick |
last post by:
Hi,
I would like to make my application to automatically
check on updates from a source and if any, downloads it
and automatically updates itself with the new version.
Now because the...
|
by: Bill Smith |
last post by:
The initial row is inserted with the colPartNum column containing a valid
LIKE pattern, such as (without the single quotes) 'AB%DE'.
I want to update the column value with the results of a query...
|
by: Nick |
last post by:
Hi,
I would like to make my application to automatically
check on updates from a source and if any, downloads it
and automatically updates itself with the new version.
Now because the...
|
by: DanWeaver |
last post by:
I have a page where layout of buttons and listboxes etc is important -
I would like to make use of Ajax Update panel to asynchronously update
various part of the page- in Vis studio whenever I use...
|
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ Topic - How do I prompt a "Save As" dialog for an
accepted mime type?...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |