pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Jdbc4ResultSet getClob and getBlob are calling getLong internally
6+ messages / 3 participants
[nested] [flat]

* Jdbc4ResultSet getClob and getBlob are calling getLong internally
@ 2010-02-01 18:53  Nedim Cholich <nedim@cholich.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Nedim Cholich @ 2010-02-01 18:53 UTC (permalink / raw)
  To: pgsql-jdbc

Server 8.4 on Ubuntu
Driver type 4 version 8.4-701

After getting 'org.postgresql.util.PSQLException: Bad value for type
long' I found these two methods in Jdbc4ResultSet:

    public java.sql.Clob getClob(int i) throws SQLException
    {
        checkResultSet(i);
        if (wasNullFlag)
            return null;

        return new Jdbc4Clob(connection, getLong(i));
    }

    public java.sql.Blob getBlob(int i) throws SQLException
    {
        checkResultSet(i);
        if (wasNullFlag)
            return null;

        return new Jdbc4Blob(connection, getLong(i));
    }

Calling getLong here has to be wrong?



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

* Re: Jdbc4ResultSet getClob and getBlob are calling getLong internally
@ 2010-02-01 20:15  Kris Jurka <books@ejurka.com>
  parent: Nedim Cholich <nedim@cholich.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Kris Jurka @ 2010-02-01 20:15 UTC (permalink / raw)
  To: Nedim Cholich <nedim@cholich.com>; +Cc: pgsql-jdbc



On Mon, 1 Feb 2010, Nedim Cholich wrote:

> After getting 'org.postgresql.util.PSQLException: Bad value for type
> long' I found these two methods in Jdbc4ResultSet:
>
>    public java.sql.Clob getClob(int i) throws SQLException
>    {
>        return new Jdbc4Clob(connection, getLong(i));
>    }
>
> Calling getLong here has to be wrong?
>

No.  Large Objects are not stored directly inline, but as a pointer to 
other storage.  The getLong is retrieving the external storage which 
Jdbc4Clob will then stream from the server on demand.  You are probably 
trying to call getClob on a text or varchar column and that's not going to 
work.  It might be nice to provide that interface, but there's no benefit 
(other than compatibility) to the user.  If you have text data stored 
inline, then it's already been transferred over to the client side in the 
ResultSet, so there's no point in using a streaming interface.

Kris Jurka



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

* Re: Jdbc4ResultSet getClob and getBlob are calling getLong internally
@ 2010-02-01 20:39  Nedim Cholich <nedim@cholich.com>
  parent: Kris Jurka <books@ejurka.com>
  0 siblings, 2 replies; 6+ messages in thread

From: Nedim Cholich @ 2010-02-01 20:39 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc

On Mon, Feb 1, 2010 at 15:15, Kris Jurka <books@ejurka.com> wrote:
> On Mon, 1 Feb 2010, Nedim Cholich wrote:
>> After getting 'org.postgresql.util.PSQLException: Bad value for type
>> long' I found these two methods in Jdbc4ResultSet:
>>
>>   public java.sql.Clob getClob(int i) throws SQLException
>>   {
>>       return new Jdbc4Clob(connection, getLong(i));
>>   }
>>
>> Calling getLong here has to be wrong?
>>
>
> No.  Large Objects are not stored directly inline, but as a pointer to other
> storage.  The getLong is retrieving the external storage which Jdbc4Clob
> will then stream from the server on demand.  You are probably trying to call
> getClob on a text or varchar column and that's not going to work.  It might
> be nice to provide that interface, but there's no benefit (other than
> compatibility) to the user.  If you have text data stored inline, then it's
> already been transferred over to the client side in the ResultSet, so
> there's no point in using a streaming interface.

Yes, it's a TEXT column and yes I'm calling rs.getClob(columnName);

What am I suppose to call instead?

The above call produces:
... blah ...
Caused by: org.postgresql.util.PSQLException: Bad value for type long
: url=http://<removed;
	at org.postgresql.jdbc2.AbstractJdbc2ResultSet.toLong(AbstractJdbc2ResultSet.java:2796)
	at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getLong(AbstractJdbc2ResultSet.java:2019)
	at org.postgresql.jdbc4.Jdbc4ResultSet.getClob(Jdbc4ResultSet.java:43)
	at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getClob(AbstractJdbc2ResultSet.java:384)

getFixedString(columnIndex) method called from
AbstractJdbc2ResultSet:2019 is returning an actual column value
(String) which toLong is trying to convert to long and failing.

Thanks!

What am I missing?



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

* Re: Jdbc4ResultSet getClob and getBlob are calling getLong internally
@ 2010-02-01 20:42  Kris Jurka <books@ejurka.com>
  parent: Nedim Cholich <nedim@cholich.com>
  1 sibling, 1 reply; 6+ messages in thread

From: Kris Jurka @ 2010-02-01 20:42 UTC (permalink / raw)
  To: Nedim Cholich <nedim@cholich.com>; +Cc: pgsql-jdbc

On 2/1/2010 12:39 PM, Nedim Cholich wrote:
>
> Yes, it's a TEXT column and yes I'm calling rs.getClob(columnName);
>
> What am I suppose to call instead?
>

getString

Kris Jurka



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

* Re: Jdbc4ResultSet getClob and getBlob are calling getLong internally
@ 2010-02-01 20:44  Nedim Cholich <nedim@cholich.com>
  parent: Kris Jurka <books@ejurka.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Nedim Cholich @ 2010-02-01 20:44 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc

On Mon, Feb 1, 2010 at 15:42, Kris Jurka <books@ejurka.com> wrote:
> On 2/1/2010 12:39 PM, Nedim Cholich wrote:
>> Yes, it's a TEXT column and yes I'm calling rs.getClob(columnName);
>> What am I suppose to call instead?
>
> getString

Ahhh. Thanks.

BTW, I'm converting an app from Mysql to Postgresql and this is
definitely different between two servers.



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

* Re: Jdbc4ResultSet getClob and getBlob are calling getLong internally
@ 2010-02-01 20:45  Kevin Grittner <Kevin.Grittner@wicourts.gov>
  parent: Nedim Cholich <nedim@cholich.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Kevin Grittner @ 2010-02-01 20:45 UTC (permalink / raw)
  To: Nedim Cholich <nedim@cholich.com>; +Cc: pgsql-jdbc

Nedim Cholich <nedim@cholich.com> wrote:
 
> Yes, it's a TEXT column and yes I'm calling
> rs.getClob(columnName);
> 
> What am I suppose to call instead?
 
In PostgreSQL a text column is not a BLOB or CLOB.
Try rs.getString(columnName);
 
For BLOB behavior, see large objects:
 
http://www.postgresql.org/docs/8.4/interactive/largeobjects.html
 
-Kevin



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


end of thread, other threads:[~2010-02-01 20:45 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-02-01 18:53 Jdbc4ResultSet getClob and getBlob are calling getLong internally Nedim Cholich <nedim@cholich.com>
2010-02-01 20:15 ` Kris Jurka <books@ejurka.com>
2010-02-01 20:39   ` Nedim Cholich <nedim@cholich.com>
2010-02-01 20:42     ` Kris Jurka <books@ejurka.com>
2010-02-01 20:44       ` Nedim Cholich <nedim@cholich.com>
2010-02-01 20:45     ` Kevin Grittner <Kevin.Grittner@wicourts.gov>

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