pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedJDBC Array double precision [] error
6+ messages / 3 participants
[nested] [flat]
* JDBC Array double precision [] error
@ 2013-03-31 22:06 Juan Pablo Cook <juampick@gmail.com>
0 siblings, 2 replies; 6+ messages in thread
From: Juan Pablo Cook @ 2013-03-31 22:06 UTC (permalink / raw)
To: pgsql-jdbc
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! ;)
^ permalink raw reply [nested|flat] 6+ messages in thread
* Fwd: JDBC Array double precision [] error
@ 2013-03-31 22:08 Juan Pablo Cook <juampick@gmail.com>
parent: Juan Pablo Cook <juampick@gmail.com>
1 sibling, 1 reply; 6+ messages in thread
From: Juan Pablo Cook @ 2013-03-31 22:08 UTC (permalink / raw)
To: pgsql-general@postgresql.org
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! ;)
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Fwd: JDBC Array double precision [] error
@ 2013-03-31 22:38 Hannes Erven <hannes@erven.at>
parent: Juan Pablo Cook <juampick@gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: Hannes Erven @ 2013-03-31 22:38 UTC (permalink / raw)
To: pgsql-general@postgresql.org; +Cc: juampick@gmail.com
Hi Juan Pablo,
> double[] array = (double[]) rs1.getArray("histograma").getArray();
> java.lang.ClassCastException: [Ljava.lang.Double; cannot be cast to [D
The error message already tells you the solution: use Double, not double.
Like this:
Double[] array = (Double[]) rs1.getArray("histograma").getArray();
Best regards,
-hannes
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Fwd: JDBC Array double precision [] error
@ 2013-03-31 22:49 Juan Pablo Cook <juampick@gmail.com>
parent: Hannes Erven <hannes@erven.at>
0 siblings, 0 replies; 6+ messages in thread
From: Juan Pablo Cook @ 2013-03-31 22:49 UTC (permalink / raw)
To: Hannes Erven <hannes@erven.at>; +Cc: pgsql-general@postgresql.org
Hi Hannes...
Thanks a lot for your help!
I was stuck being many many hours trying and googling it the problem but
didn't realize that.
This: *Double[] array = (Double[]) rs1.getArray("histograma").get**Array();*
solve my problem!
Thanks again!!
Juan Cook
On Sun, Mar 31, 2013 at 7:38 PM, Hannes Erven <hannes@erven.at> wrote:
> Hi Juan Pablo,
>
>
>
> > double[] array = (double[]) rs1.getArray("histograma").**getArray();
>
>> java.lang.ClassCastException: [Ljava.lang.Double; cannot be cast to [D
>>
>
>
> The error message already tells you the solution: use Double, not double.
>
> Like this:
> Double[] array = (Double[]) rs1.getArray("histograma").**getArray();
>
>
> Best regards,
>
> -hannes
>
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: JDBC Array double precision [] error
@ 2013-04-01 06:28 Nicholas White <n.j.white@gmail.com>
parent: Juan Pablo Cook <juampick@gmail.com>
1 sibling, 1 reply; 6+ messages in thread
From: Nicholas White @ 2013-04-01 06:28 UTC (permalink / raw)
To: Juan Pablo Cook <juampick@gmail.com>; +Cc: 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#toA...)
...
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! ;)
>
>
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: JDBC Array double precision [] error
@ 2013-04-01 21:19 Juan Pablo Cook <juampick@gmail.com>
parent: Nicholas White <n.j.white@gmail.com>
0 siblings, 0 replies; 6+ messages in thread
From: Juan Pablo Cook @ 2013-04-01 21:19 UTC (permalink / raw)
To: Nicholas White <n.j.white@gmail.com>; +Cc: pgsql-jdbc
Thanks everyone! that's help a lot ;) Double[] instead of the primitive
double[].
Thanks!
JP
On Mon, Apr 1, 2013 at 3:28 AM, Nicholas White <n.j.white@gmail.com> wrote:
> 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#toA...)
> ...
>
>
> 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! ;)
>>
>>
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2013-04-01 21:19 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-03-31 22:06 JDBC Array double precision [] error Juan Pablo Cook <juampick@gmail.com>
2013-03-31 22:08 ` Juan Pablo Cook <juampick@gmail.com>
2013-03-31 22:38 ` Hannes Erven <hannes@erven.at>
2013-03-31 22:49 ` Juan Pablo Cook <juampick@gmail.com>
2013-04-01 06:28 ` Nicholas White <n.j.white@gmail.com>
2013-04-01 21:19 ` Juan Pablo Cook <juampick@gmail.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