From: | Prasanth <dbadmin(at)nqadmin(dot)com> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Bad value for type date |
Date: | 2005-08-19 19:25:33 |
Message-ID: | 4306322D.7090505@nqadmin.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Hi,
Below is a small program to test the JDBC date issue I have having.
I am able to set the date "2/1/10000". But it fails to retrieve it.
If it is invalid date then it should not even update the database right?
String sql = "SELECT * FROM table where = 9159;";
JdbcRowSetImpl rs = new JdbcRowSetImpl(connection);
rs.setCommand(sql);
rs.execute();
rs.next();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MONTH, 1);
calendar.set(Calendar.DATE, 1);
calendar.set(Calendar.YEAR, 10000);
Date date = new Date(calendar.getTimeInMillis());
System.out.println(date);
rs.updateDate("end_date", date);
rs.updateRow();
System.out.println("Date: " + rs.getDate("end_date") + " " +
rs.getString("plan_id") +" "+ rs.getDate("start_date"));
This causes
org.postgresql.util.PSQLException: Bad value for type date :
at org.postgresql.jdbc2.TimestampUtils.loadCalendar(TimestampUtils.java:155)
at org.postgresql.jdbc2.TimestampUtils.toDate(TimestampUtils.java:245)
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.getDate(AbstractJdbc2ResultSet.java:2075)
at com.sun.rowset.JdbcRowSetImpl.getDate(JdbcRowSetImpl.java:1087)
at com.sun.rowset.JdbcRowSetImpl.getDate(JdbcRowSetImpl.java:1403)
at PostgresDate.main(PostgresDate.java:30)
Caused by: java.lang.NumberFormatException
at org.postgresql.jdbc2.TimestampUtils.number(TimestampUtils.java:407)
at org.postgresql.jdbc2.TimestampUtils.loadCalendar(TimestampUtils.java:47)
... 5 more
When I query the database using psql
Below is what is in the database
| 2000-01-01 | 10000-02-01 | 9159 |
So it did update the database.
After running this I ran the following program.
String sql = "SELECT * FROM accounting_periods where plan_id = 9159;";
JdbcRowSetImpl rs = new JdbcRowSetImpl(connection);
rs.setCommand(sql);
rs.execute();
rs.next();
System.out.println("Date: " + rs.getDate("end_date") + " " + rs.getString("id")
+" "+ rs.getDate("start_date"));
Output:
Date:
Thanks,
-Prasanth.
From | Date | Subject | |
---|---|---|---|
Next Message | Oliver Jowett | 2005-08-19 21:53:24 | Re: Bad value for type date |
Previous Message | Kris Jurka | 2005-08-19 17:52:46 | Re: COPY support survey |