Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving postgresql arrays using JDBC

I have a table like this

  list     |  id  | 
-----------+--------
 {930,23}  |  1   |
 {2012,1}  |  2   |
 {5943}    |  3   |
 {6148}    |  4   |
 {1003}    |  5   |

Now, I'd like to use JDBC to retrieve the first column. I've learned that we can use java.sql.Array to do that. (http://docs.oracle.com/javase/tutorial/jdbc/basics/array.html#retrieving_array), but when I declare the Array object like this:

import java.sql.Array;

while(rs.next())
    Array arr;

It issues a compile error:

[javac] /home/xxx.java:291: error: not a statement
[javac]             Array arr;
[javac]             ^
[javac] /home/xxx.java:291: error: ';' expected
[javac]             Array arr;
[javac]                  ^
[javac] /home/xxx.java:291: error: not a statement
[javac]             Array arr;
[javac]                   ^

It seems that Java is not recognizing the data type java.sql.Array. Anyone knows why? Thanks a lot!

like image 940
Yang Avatar asked Feb 25 '26 03:02

Yang


1 Answers

You should use curly brackets with your while statements:

while (rs.next()) {
    Array arr;  // Add more code here.
}
like image 108
Mark Byers Avatar answered Feb 27 '26 16:02

Mark Byers