Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / February 2006

Tip: Looking for answers? Try searching our database.

jdbc date format error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
balleyman47@gmail.com - 10 Feb 2006 00:46 GMT
getting the following error when executing an insert statement:

java.lang.IllegalArgumentException: Date/Time must be JDBC format

running on UDB 8.2 fix pack 10 using IBM type IV driver.
Query in JAVA program works successfully in old environment, converting
from UDB 7 to above UDB version.

Values passed during execution of insert statement (inserting into
table A) are derived from date fields on another table B but will
default to the following hard coded value when no date exists on table
B:
"01/01/1970"

Example Query:

if (date1 == null)
    date1 = "01/01/1970";

insert into A
Values(date1);
Phil Sherman - 10 Feb 2006 04:08 GMT
The error message indicates that date1 must be a java.sql Date variable.
If you want to avoid using depreciated functions, you should instantiate
a java.util.Calendar object, set the date (and time) you want, then use
its getTimeInMillis() method to get the value needed to create the
java.sql.Date object. Java dates are based on milliseconds since the
start of the current epoch - Jan 1, 1970 - 00:00:00. Since this is your
default date, you should be able to use:
 import java.sql.*;
 Date date1 = new Date(0);

Check that this works before using it. On my system, Date(0) gives:
 12/31/1969 - 19:00:00
This is probably caused by the offset between GMT and EST.

 Calendar c1 - Calendar.getInstance();
 c1.set(1970,c1.JANUARY,01,00,00,00);
 Date date2 = new Date(c1.getTimeInMillis());

Using the Calendar object creates the 1/1/1970 date you want.

If you also have an import for java.util.*; you will need to use:
 java.sql.Date date1 = new java.sql.Date(c1.getTimeInMillis());

Phil Sherman

> getting the following error when executing an insert statement:
>
[quoted text clipped - 17 lines]
> insert into A
> Values(date1);
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.