pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bendik Rognlien Johansen <bensmailinglists@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: Retrieving arrays
Date: Wed, 11 Oct 2006 13:54:10 +0200
Message-ID: <FE77BF07-00B0-4F11-82C4-243C5299FC8B@gmail.com> (raw)
In-Reply-To: <1160503178.8082.10.camel@archimedes>
References: <533747B3-BC3C-4D07-A2B8-A3C86B85C718@gmail.com>
	<1160503178.8082.10.camel@archimedes>

Ok, thanks! So, that probably means I can not do this sort of thing  
with Generics?

Is there any way the driver could get the same behavior as the driver  
used in PL/Java? In PL/Java i can do:
return (String[]) rs.getObject(column);

On Oct 10, 2006, at 7:59 PM, Mark Lewis wrote:

> Java 5 doesn't support auto-boxing an int[] as an Integer[].
>
> -- Mark Lewis
>
> On Tue, 2006-10-10 at 15:15 +0200, Bendik Rognlien Johansen wrote:
>> Hello,
>> I wrote this method to read arrays from my result set.
>>
>>
>> public class MyClass {
>>    public <T> T[] getArray(ResultSet rs, String column) throws
>> Exception {
>>      if(rs.getArray(column) != null) {
>>        return (T[]) rs.getArray(column).getArray();
>>      }
>>      return null;
>>    }
>> }
>>
>>
>>
>> I call i like this:
>>
>> String[] values = MyClass.<String>getArray(rs,  
>> "myStringArrayColumn"));
>>
>>   This works fine. ( "myStringArrayColumn" is of type character
>> varying(64)[])
>>
>>
>> But, when I call:
>>
>> Integer[] values = MyClass.<Integer>getArray(rs,
>> "myIntegerArrayColumn"));
>> ( "myIntegerArrayColumn" is of type integer[])
>>
>>
>> I get a:
>> java.lang.ClassCastException: [I
>>
>>
>> Any ideas?
>>
>> Thanks
>>
>> ---------------------------(end of  
>> broadcast)---------------------------
>> TIP 4: Have you searched our list archives?
>>
>>                http://archives.postgresql.org
>
> ---------------------------(end of  
> broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faq




view thread (11+ messages)  latest in thread

Message-ID: <FE77BF07-00B0-4F11-82C4-243C5299FC8B@gmail.com>
Permalink:  ../FE77BF07-00B0-4F11-82C4-243C5299FC8B@gmail.com/
Also on:    postgresql.org/message-id/FE77BF07-00B0-4F11-82C4-243C5299FC8B@gmail.com

 · 

reply

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: bensmailinglists@gmail.com
  Subject: Re: Retrieving arrays
  In-Reply-To: <FE77BF07-00B0-4F11-82C4-243C5299FC8B@gmail.com>
  References: <533747B3-BC3C-4D07-A2B8-A3C86B85C718@gmail.com> <1160503178.8082.10.camel@archimedes> <FE77BF07-00B0-4F11-82C4-243C5299FC8B@gmail.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