From: Oliver Jowett <oliver@opencloud.com>
To: dbadmin@nqadmin.com
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Bad value for type date
Date: Sun, 21 Aug 2005 01:10:56 +1200
Message-ID: <43072BE0.9000306@opencloud.com> (raw)
In-Reply-To: <4306322D.7090505@nqadmin.com>
References: <4306322D.7090505@nqadmin.com>
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();
}
}
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: oliver@opencloud.com, dbadmin@nqadmin.com
Subject: Re: Bad value for type date
In-Reply-To: <43072BE0.9000306@opencloud.com>
References: <4306322D.7090505@nqadmin.com> <43072BE0.9000306@opencloud.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