473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

jdbc date format error

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);

Feb 10 '06 #1
1 11181
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

ba*********@gmail.com wrote:
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);

Feb 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
1
by: Andrea | last post by:
Hello, I spent now several hours searching the google groups without finding an solution. I am kind of Newbie to DB2 and JSP and therefore working with JSP4Dummies (not sure whether I should...
2
by: charl | last post by:
Hi, My apologies in advance if my terminology is slightly confused, I am new to all this. We have previously been running some SQL on DB2 (v7) utilising a type 3 driver, and have made the...
1
by: Dr X | last post by:
I have a problem updating date values using Java via JDBC-ODBC to Access. <snip rs.updateTimestamp(theIndex,theTimeStamp); rs.updateRow(); <snip> (where theTimeStamp is a valid Java Timestamp...
9
by: Kenevel | last post by:
Hi everyone, Has anyone come across a problem where on Linux using DB2 9.1 Express- C with the packaged jcc-JDBC driver that it fails correctly to parse a returned date value? I'm simply calling...
5
by: pmagee | last post by:
I am trying to convert a date from string format into the SQL date format. This seems to work fine as it prints out as 1999-01-01 - see code below. I then try to insert this as a variable into my...
0
by: Lars Hylleberg | last post by:
In my company we are runing java Webshere applications on Windows platform and connecting to DB2 V8 on z/OS mainframe. Until now we have used the type 2 JDBC driver, which are using the DB2 Connect...
1
by: wnaveenkumar | last post by:
package com.trewport.orderprocess.action; import java.io.*; import java.sql.*; import java.util.*; import java.util.Date; import java.lang.Object; import javax.servlet.*; import...
19
by: robtyketto | last post by:
Greetings, I have the following code below which allows the date to be added via a JDBC connection as a STRING. The value of dateString is inserted into the MS ACCESS database. What is the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
jinu1996
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.