Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JDBC Array double precision [] error

24 views
Skip to first unread message

Juan Pablo Cook

unread,
Mar 31, 2013, 6:06:43 PM3/31/13
to
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! ;)

Nicholas White

unread,
Apr 1, 2013, 2:28:13 AM4/1/13
to
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) ...

Juan Pablo Cook

unread,
Apr 1, 2013, 5:19:41 PM4/1/13
to
Thanks everyone! that's help a lot ;) Double[] instead of the primitive double[].

Thanks!

JP
0 new messages