Getting 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 would like to use JDBC to retrieve the first column. I found out that we can use java.sql.Array for this. ( http://docs.oracle.com/javase/tutorial/jdbc/basics/array.html#retrieving_array ), but when I declare an Array object as follows:

import java.sql.Array;

while(rs.next())
    Array arr;

It throws a compilation 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]                   ^

Java doesn't seem to recognize the java.sql.Array data type. Does anyone know why? Many thanks!

+3
source share
1 answer

You should use curly braces with your while statements:

while (rs.next()) {
    Array arr;  // Add more code here.
}
+2
source

All Articles