Re: how do you update a java.sql.date type in an ms access database
- From: "Bjorn Abelli" <bjorn_abelli@xxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 9 Nov 2005 21:49:33 +0100
"chose" wrote...
> when i update a row in an access database the date field
> does not update to the correct date it brings up some
> funny date which i dont know where it comes from.
It comes from db's attempt to parse an invalid date-string...
In Access/Jet, it needs to be enclosed within #:s, and with the date parts
in a specific order...
Another thing is that java.sql.Date only contains the date part, whereas the
DateTime data type in Access/Jet is more like a java.sql.Timestamp.
> Below is the method i use to update. maybe
> the date types are not compatable?
Well, partly, but you're not using the date AS a date in the SQL statement,
but as a String. This will in most cases lead to errors, as the parsing of
such is left to the database, not the driver...
> s.executeUpdate("update Rooms set CustomerId=" + custID
> + ", BookINDate = " + bkInDate + ", Occupied = " + yes
> + " where RoomNo = " + rNumber + " ");
It's really bad practice to concatenate the string for an SQL statement in
that way, because of differences between different dbs. Instead you should
use a parameterized statement.
Use java.sql.Timestamp instead of java.sql.Date.
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Timestamp.html
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Date.html
Read up on how to use a PreparedStatement, and it will solve your problem.
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/PreparedStatement.html
// Bjorn A
.
- Prev by Date: Re: Help with java code for Box Class
- Next by Date: Re: Java Session in JSP
- Previous by thread: Help with BlueJ: editing and auto indenting all including {}'s
- Next by thread: Re: how do you update a java.sql.date type in an ms access database
- Index(es):
Relevant Pages
|