pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedBad value for type date
9+ messages / 2 participants
[nested] [flat]
* Bad value for type date
@ 2005-08-19 19:25 Prasanth <dbadmin@nqadmin.com>
0 siblings, 2 replies; 9+ messages in thread
From: Prasanth @ 2005-08-19 19:25 UTC (permalink / raw)
To: 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.
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Bad value for type date
@ 2005-08-19 21:53 Oliver Jowett <oliver@opencloud.com>
parent: Prasanth <dbadmin@nqadmin.com>
1 sibling, 1 reply; 9+ messages in thread
From: Oliver Jowett @ 2005-08-19 21:53 UTC (permalink / raw)
To: dbadmin@nqadmin.com; +Cc: pgsql-jdbc
Prasanth wrote:
> Below is a small program to test the JDBC date issue I have having.
What driver version are you using?
-O
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Bad value for type date
@ 2005-08-20 04:49 Prasanth <dbadmin@nqadmin.com>
parent: Oliver Jowett <oliver@opencloud.com>
0 siblings, 0 replies; 9+ messages in thread
From: Prasanth @ 2005-08-20 04:49 UTC (permalink / raw)
To: Oliver Jowett <oliver@opencloud.com>; +Cc: pgsql-jdbc
I am using postgresql-8.0-310.jdbc3.jar
-Prasanth.
-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Oliver Jowett
Sent: Friday, August 19, 2005 4:53 PM
To: dbadmin@nqadmin.com
Cc: pgsql-jdbc@postgresql.org
Subject: Re: [JDBC] Bad value for type date
Prasanth wrote:
> Below is a small program to test the JDBC date issue I have having.
What driver version are you using?
-O
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Bad value for type date
@ 2005-08-20 13:10 Oliver Jowett <oliver@opencloud.com>
parent: Prasanth <dbadmin@nqadmin.com>
1 sibling, 1 reply; 9+ messages in thread
From: Oliver Jowett @ 2005-08-20 13:10 UTC (permalink / raw)
To: dbadmin@nqadmin.com; +Cc: pgsql-jdbc
Prasanth wrote:
> 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?
I can't reproduce this; the attached testcase produces this against my
8.0 install:
Inserting date: 10000-02-01 AD +1300
Got date: 10000-02-01 AD +1300
Got date: 10000-02-01 AD +1300
I get this using both the -310 driver and a build from CVS HEAD.
You'll need to give us a compilable testcase that shows the problem to
take this any further. The code you provided originally doesn't compile
out-of-the-box, is missing schema information, and has a syntactically
incorrect query..
It'd also help if you can reproduce your problem without involving a
RowSet implementation.
-O
Attachments:
TestDate2.java (text/plain, 1.2K) download
import java.sql.*;
import java.util.Calendar;
public class TestDate2 {
public static void main(String[] args) throws Exception {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection(args[0]);
Statement stmt = conn.createStatement();
try {
stmt.executeUpdate("DROP TABLE testdate2");
} catch (SQLException e) {}
stmt.executeUpdate("CREATE TABLE testdate2(d date)");
stmt.executeUpdate("INSERT INTO testdate2(d) VALUES ('10000/02/01')");
PreparedStatement ps = conn.prepareStatement("INSERT INTO testdate2(d) VALUES (?)");
Calendar c = Calendar.getInstance();
c.set(Calendar.MONTH, 1);
c.set(Calendar.DATE, 1);
c.set(Calendar.YEAR, 10000);
Date d = new Date(c.getTimeInMillis());
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd G Z");
System.out.println("Inserting date: " + sdf.format(d));
ps.setDate(1, d);
ps.executeUpdate();
ResultSet rs = stmt.executeQuery("SELECT d FROM testdate2");
while (rs.next()) {
d = rs.getDate(1);
System.out.println("Got date: " + sdf.format(d));
}
rs.close();
stmt.close();
conn.close();
}
}
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Bad value for type date
@ 2005-08-20 16:16 Prasanth <dbadmin@nqadmin.com>
parent: Oliver Jowett <oliver@opencloud.com>
0 siblings, 2 replies; 9+ messages in thread
From: Prasanth @ 2005-08-20 16:16 UTC (permalink / raw)
To: Oliver Jowett <oliver@opencloud.com>; +Cc: pgsql-jdbc
Hi,
Below if the code with result set to reproduce the problem.
Thanks,
-Prasanth.
import java.sql.*;
import java.util.Calendar;
public class TestDate2 {
public static void main(String[] args) throws Exception {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection(args[0]);
Statement stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
try {
stmt.executeUpdate("DROP TABLE testdate2");
} catch (SQLException e) {}
stmt.executeUpdate("CREATE TABLE testdate2(id int4 primary key, d
date)");
stmt.executeUpdate("INSERT INTO testdate2(id, d) VALUES
(1,'10000/02/01')");
Calendar c = Calendar.getInstance();
c.set(Calendar.MONTH, 1);
c.set(Calendar.DATE, 1);
c.set(Calendar.YEAR, 10000);
Date d = new Date(c.getTimeInMillis());
ResultSet rs = stmt.executeQuery("SELECT * FROM testdate2");
while (rs.next()) {
rs.updateDate("d", d);
rs.updateRow();
d = rs.getDate("d");
System.out.println("Got date: " + d);
}
rs.close();
stmt.close();
conn.close();
}
}
-----Original Message-----
From: Oliver Jowett [mailto:oliver@opencloud.com]
Sent: Saturday, August 20, 2005 8:11 AM
To: dbadmin@nqadmin.com
Cc: pgsql-jdbc@postgresql.org
Subject: Re: [JDBC] Bad value for type date
Prasanth wrote:
> 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?
I can't reproduce this; the attached testcase produces this against my
8.0 install:
Inserting date: 10000-02-01 AD +1300
Got date: 10000-02-01 AD +1300
Got date: 10000-02-01 AD +1300
I get this using both the -310 driver and a build from CVS HEAD.
You'll need to give us a compilable testcase that shows the problem to
take this any further. The code you provided originally doesn't compile
out-of-the-box, is missing schema information, and has a syntactically
incorrect query..
It'd also help if you can reproduce your problem without involving a
RowSet implementation.
-O
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Bad value for type date
@ 2005-08-20 21:40 Oliver Jowett <oliver@opencloud.com>
parent: Prasanth <dbadmin@nqadmin.com>
1 sibling, 1 reply; 9+ messages in thread
From: Oliver Jowett @ 2005-08-20 21:40 UTC (permalink / raw)
To: Prasanth <dbadmin@nqadmin.com>; +Cc: pgsql-jdbc
Prasanth wrote:
> Below if the code with result set to reproduce the problem.
Thanks, I can reproduce it now.
It looks like a bug with updating the ResultSet's internal state after
updating via updateRow(). If you get a fresh copy of the row from the
database, it's fine.
-O
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Bad value for type date
@ 2005-08-20 23:09 Oliver Jowett <oliver@opencloud.com>
parent: Oliver Jowett <oliver@opencloud.com>
0 siblings, 0 replies; 9+ messages in thread
From: Oliver Jowett @ 2005-08-20 23:09 UTC (permalink / raw)
To: Prasanth <dbadmin@nqadmin.com>; +Cc: pgsql-jdbc
Oliver Jowett wrote:
> Prasanth wrote:
>
>
>>Below if the code with result set to reproduce the problem.
>
>
> Thanks, I can reproduce it now.
>
> It looks like a bug with updating the ResultSet's internal state after
> updating via updateRow(). If you get a fresh copy of the row from the
> database, it's fine.
I've fixed this in CVS HEAD.
Thanks for the report!
-O
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Bad value for type date
@ 2005-08-20 23:46 Oliver Jowett <oliver@opencloud.com>
parent: Prasanth <dbadmin@nqadmin.com>
1 sibling, 1 reply; 9+ messages in thread
From: Oliver Jowett @ 2005-08-20 23:46 UTC (permalink / raw)
To: Prasanth <dbadmin@nqadmin.com>; +Cc: pgsql-jdbc
Prasanth wrote:
> Below if the code with result set to reproduce the problem.
As a workaround for the -310 driver, call refreshRow() after updateRow()
and you should be able to retrieve values correctly.
-O
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Bad value for type date
@ 2005-08-22 15:02 Prasanth <dbadmin@nqadmin.com>
parent: Oliver Jowett <oliver@opencloud.com>
0 siblings, 0 replies; 9+ messages in thread
From: Prasanth @ 2005-08-22 15:02 UTC (permalink / raw)
To: Oliver Jowett <oliver@opencloud.com>; +Cc: pgsql-jdbc
Hi Oliver,
Thank you very much.
-Prasanth.
Oliver Jowett wrote:
> Prasanth wrote:
>
>
>>Below if the code with result set to reproduce the problem.
>
>
> As a workaround for the -310 driver, call refreshRow() after updateRow()
> and you should be able to retrieve values correctly.
>
> -O
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match
>
>
^ permalink raw reply [nested|flat] 9+ messages in thread
end of thread, other threads:[~2005-08-22 15:02 UTC | newest]
Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-08-19 19:25 Bad value for type date Prasanth <dbadmin@nqadmin.com>
2005-08-19 21:53 ` Oliver Jowett <oliver@opencloud.com>
2005-08-20 04:49 ` Prasanth <dbadmin@nqadmin.com>
2005-08-20 13:10 ` Oliver Jowett <oliver@opencloud.com>
2005-08-20 16:16 ` Prasanth <dbadmin@nqadmin.com>
2005-08-20 21:40 ` Oliver Jowett <oliver@opencloud.com>
2005-08-20 23:09 ` Oliver Jowett <oliver@opencloud.com>
2005-08-20 23:46 ` Oliver Jowett <oliver@opencloud.com>
2005-08-22 15:02 ` Prasanth <dbadmin@nqadmin.com>
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