From: Prasanth <dbadmin@nqadmin.com>
To: pgsql-jdbc@postgresql.org
Subject: Bad value for type date
Date: Fri, 19 Aug 2005 14:25:33 -0500
Message-ID: <4306322D.7090505@nqadmin.com> (raw)
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: dbadmin@nqadmin.com
Subject: Re: Bad value for type date
In-Reply-To: <4306322D.7090505@nqadmin.com>
References: <4306322D.7090505@nqadmin.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox