Home arrow static arrow Java Programming [Archive] - JAVA dates & SQL
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - JAVA dates & SQL
This topic has 2 replies on 1 page.

Registered: 6/19/04
JAVA dates & SQL  
Jun 19, 2004 2:18 AM


I have some questions about the Date classes an SQL:

1.) I have the following data year, month, day (all int).

I want to make an object of the java.util.Date class. Because the constructor expects a long number in miliseconds that have past since 1.1.1970 0:00:00 a transformation has to be done.

That SHOULD handle the Calendar class.
I have it that way (let's say we are the 8.7.2004):

Calendar pretvorba = Calendar.getInstance();
Date mojDatum = pretvorba.getTime();

Now when I print mojDatum with the toString() metod I get:
which I don't want to get(I wan't 2004-07-08(if its YYYY-MM-DD)). Does anybody know what's wrong??????????

2.) I need the date to save it in a Database. Therefore I need to convert java.util.Date into java.sql.Date. I'm doing it so:

java.sql.Date mojSqlDatum = new java.sql.Date(mojDatum.getTimeInMillis());

Now i comunicate with the Database so:

Resultset base = query.("SELECT * FROM dnevi");
base.updateDate("datumOd", mojSqlDatum);

And I get the error: ERROR IN ROW !!!!!!!!!!!

I'm able to update all other datatypes (String...) whit their update methods(updateString).
Does anybody have the idea why it won't work? I'm despret.

How does the Date type look like in SQL??? I mean the format.

Registered: 7/22/99
Re: JAVA dates & SQL  
Jun 19, 2004 5:27 AM (reply 1 of 2)

1) You must have called the set method wrong. The parameters are year, month, day in that order:
c = Calendar.getInstance();c.set(2004, Calendar.JULY, 8);print(c.getTime()); // prints July 8, 2004

2 & 3) No idea really, but I have the feeling this depends on your database and JDBC driver.

Registered: 10.09.03
Re: JAVA dates & SQL  
Jun 19, 2004 5:51 AM (reply 2 of 2)

3) most DBMS systems expect the english format, so YYYY-MM-DD HH:MM:SS
This topic has 2 replies on 1 page.