pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
error: ResultSet.updateObject(timestamp in POSTGRES, DATE(7) in ORACLE )
2+ messages / 2 participants
[nested] [flat]

* error: ResultSet.updateObject(timestamp in POSTGRES, DATE(7) in ORACLE )
@ 2006-08-28 12:06  Vidas Makauskas <vms@centras.lt>
  0 siblings, 1 reply; 2+ messages in thread

From: Vidas Makauskas @ 2006-08-28 12:06 UTC (permalink / raw)
  To: pgsql-jdbc

Hi,
I've upgrade SLES9 with pg73b1jdbc3.jar to SLES10 with 
postgresql-8.1-404.jdbc3.jar

ResultSet.updateObject(timestamp in POSTGRES, DATE(7) from ORACLE database 
via OJDBC13.JAR )
begin produce error in ResultSet.insertRow():
Exception in thread "main" java.lang.ClassCastException
        at 
org.postgresql.jdbc2.AbstractJdbc2ResultSet.updateRowBuffer(AbstractJdbc2ResultSet.java:1727)
        at 
org.postgresql.jdbc2.AbstractJdbc2ResultSet.insertRow(AbstractJdbc2ResultSet.java:832)
.........

CAST ( TRUNC ( ORACLE->DATE(7), 'DD' ) AS TIMESTAMP ) in ORACLE view not 
accetable too.

There's no errors in case ResultSet.updateObject(date in POSTGRES, DATE(7) 
from ORACLE)
Vidas 





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: error: ResultSet.updateObject(timestamp in POSTGRES,
@ 2006-08-30 02:47  Kris Jurka <books@ejurka.com>
  parent: Vidas Makauskas <vms@centras.lt>
  0 siblings, 0 replies; 2+ messages in thread

From: Kris Jurka @ 2006-08-30 02:47 UTC (permalink / raw)
  To: Vidas Makauskas <vms@centras.lt>; +Cc: pgsql-jdbc



On Mon, 28 Aug 2006, Vidas Makauskas wrote:

> I've upgrade SLES9 with pg73b1jdbc3.jar to SLES10 with
> postgresql-8.1-404.jdbc3.jar
>
> ResultSet.updateObject(timestamp in POSTGRES, DATE(7) from ORACLE database
> via OJDBC13.JAR )
> begin produce error in ResultSet.insertRow():
> Exception in thread "main" java.lang.ClassCastException
>        at
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.updateRowBuffer(AbstractJdbc2ResultSet.java:1727)
>        at
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.insertRow(AbstractJdbc2ResultSet.java:832)
> .........
>

I can reproduce this using only postgresql by trying to copy a date field 
to a timestamp field.  The issue is that the updatable result set code 
assumes that if the target is a timestamp then the incoming object will 
also be a timestamp and it may safely cast that object to a 
java.sql.Timestamp.  This is not always so as shown, so the driver needs 
some more powerful conversion utilities here, something along the lines of 
PreparedStatement.setObject(index, obj, targetType) would do the trick. 
This is a low priority item for me, so I won't be working on this anytime 
soon, but here's the test case I used.

Kris Jurka

Attachments:

UpdateTypeTest.java (text/plain, 1.1K) download import java.sql.*; public class UpdateTypeTest { public static void main(String args[]) throws Exception { Class.forName("org.postgresql.Driver"); Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5810/jurka","jurka",""); Statement sourceStatement = conn.createStatement(); Statement destStatement = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); sourceStatement.execute("CREATE TEMP TABLE source(a int PRIMARY KEY, b timestamp, c date)"); destStatement.execute("CREATE TEMP TABLE dest(a int PRIMARY KEY, b timestamp, c date)"); sourceStatement.execute("INSERT INTO source values(1, now(), '2006-11-20')"); sourceStatement.execute("INSERT INTO source values(2, now(), '2004-11-20')"); ResultSet source = sourceStatement.executeQuery("SELECT a,c,b FROM source"); ResultSet dest = destStatement.executeQuery("SELECT a,b,c FROM dest"); while (source.next()) { dest.moveToInsertRow(); for (int i=1; i<=3; i++) { dest.updateObject(i, source.getObject(i)); } dest.insertRow(); } } }
^ permalink raw reply [nested|flat] 2+ messages in thread


end of thread, other threads:[~2006-08-30 02:47 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-08-28 12:06 error: ResultSet.updateObject(timestamp in POSTGRES, DATE(7) in ORACLE ) Vidas Makauskas <vms@centras.lt>
2006-08-30 02:47 ` Re: error: ResultSet.updateObject(timestamp in POSTGRES, Kris Jurka <books@ejurka.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