It is a prepared statement but I was trying to keep the Java code simple by
dealing with only strings. It seems I'll need to do the conversion in the
Java code rather than in the SQL statement.
Thanks,
Todd
"Clapham, Paul"
<pclapham@core-ma
rk.com> To
Sent by: "Java Programming on and around the
java400-l-bounces iSeries / AS400"
@midrange.com <java400-l@xxxxxxxxxxxx>
cc
2008-11-05 11:25 Subject
RE: JDBC date insert
Please respond to
Java Programming
on and around the
iSeries / AS400
<java400-l@midran
ge.com>
Well, don't do it that way. Just use a PreparedStatement. It takes care
of all those annoying details on your behalf.
java.util.Date date = // a date 11/5/2008 with time 4:02:04
PreparedStatement ps = conn.prepareStatement("insert into myfile
(cmdate, cmtime) values(?, ?)");
ps.setDate(1, new java.sql.Date(date.getTime()));
ps.setTime(2, new java.sql.Time(date.getTime()));
ps.executeUpdate();
PC2
-----Original Message-----
From: java400-l-bounces@xxxxxxxxxxxx
[mailto:java400-l-bounces@xxxxxxxxxxxx] On Behalf Of TAllen@xxxxxxxxxxxx
Sent: November 5, 2008 07:16
To: Java Programming on and around the iSeries / AS400
Subject: JDBC date insert
I am having trouble with a JDBC insert of a string into date or time
columns in a database table. The same command works fine from the SQL
green screen.
The insert statement fails with the "Data type mismatch" SQL exception.
The odd thing is that this only fails when the date or time does not
have all leading zeros.
Date of 11/14/2008 - success
Date of 11/4/2008 - error
Time of 22:00:00 - success
Time of 4:00:00 - error
The insert statement looks like this:
insert into myfile (cmdate, cmtime) values(cast('11/5/2008' as date),
cast('4:02:04' as time))
Thanks,
Todd
This communication and any transmitted documents are intended to be
confidential. If there is a problem with this transmission, please
contact the sender. If the reader of this message is not the intended
recipient, or the employee or agent responsible to deliver it to the
intended recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
--
This is the Java Programming on and around the iSeries / AS400
(JAVA400-L) mailing list To post a message email: JAVA400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at
http://archive.midrange.com/java400-l.
--
This is the Java Programming on and around the iSeries / AS400 (JAVA400-L)
mailing list
To post a message email: JAVA400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at
http://archive.midrange.com/java400-l.
This communication and any transmitted documents are intended to be confidential. If there is a problem with this transmission, please contact the sender. If the reader of this message is not the intended recipient, or the employee or agent responsible to deliver it to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.
As an Amazon Associate we earn from qualifying purchases.