Re: JDBC Array double precision [] error

From: Nicholas White <n(dot)j(dot)white(at)gmail(dot)com>
To: Juan Pablo Cook <juampick(at)gmail(dot)com>
Cc: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: JDBC Array double precision [] error
Date: 2013-04-01 06:28:13
Message-ID: CA+=vxNZTGpfvHmk+o6iim__SKvWbzSLqX1CJSxoxPMVKh8+6=Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-jdbc

getArray returns a Double[] - not a primitive double[]. You can't cast
between the two; use something like
http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/primitives/Doubles.html#toArray(java.util.Collection)
...

On Sunday, 31 March 2013, Juan Pablo Cook wrote:

> Hi everyone! I need your help with this problem.
>
> I'm using PostgreSQL 9.2 Server & the latest jdbc
> driver: postgresql-9.2-1002.jdbc4.jar
>
> I have a table with this column array:
> -- histograma double precision[]
>
> And I want to retrieve this and cast into java to double[] but I can't.
>
> This is the extract of the code:
>
> Statement stat1 = con.createStatement();
> ResultSet rs1 = stat1.executeQuery("SELECT * FROM \"Vector\");
>
> while (rs1.next()) {
>
> double[] array = (double[]) rs1.getArray("histograma").getArray();
>
> }
>
> And the error:
> "
> Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException:
> [Ljava.lang.Double; cannot be cast to [D
> "
> Also I tried to do a for loop but didn't work.
>
> Can you help me?
>
> Thanks a lot! ;)
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Marko Kreen 2013-04-01 07:25:10 Re: in C trigger function find out if column is part of primary key
Previous Message Jasen Betts 2013-04-01 06:22:43 Re: Using varchar primary keys.

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2013-04-01 10:53:52 Re: JDBC 9.2 DEV not working with Hex bytea output?
Previous Message Juan Pablo Cook 2013-03-31 22:49:06 Re: Fwd: JDBC Array double precision [] error