The moose likes JDBC and Relational Databases and the fly likes SQL Array Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SQL Array Question" Watch "SQL Array Question" New topic

SQL Array Question

Nagaraju Nookala

Joined: Mar 19, 2004
Posts: 23

In my application I want to use the Interface Array and the method getResultSet(long index, int count).

My code is given below:

int count = 0;
long index = 3;

Connection connection = null;
ResultSet resultSet = null;
ResultSet resultSet1 = null;
Statement statement = null;
Array array = null;

connection = DriverManager.getConnection("jdbc racle:thin:@localhost:1521:SID","user","password");
statement = connection.createStatement();
resultSet = statement.executeQuery("select count(*) from tblname");
while ({
count = resultSet.getInt(1);

System.out.println("Count is: " + count);


resultSet = statement.executeQuery("select * from tblname");

resultSet = array.getResultSet(index, count);

System.out.println("Column Value is: " + resultSet.getString("COLUMNNAME"));

my code is failing with a java.lang.NullPointerExceptuion at the line

resultSet = array.getResultSet(index, count);

I think I need to map the ResultSet to the Array before extracting the value from it. How can I make the resultSet map to the array and get the value from the array?

Thanks in advance.

Karthikeyan Rajendraprasad
Ranch Hand

Joined: Apr 16, 2003
Posts: 70
array is not initialized.
[ August 12, 2005: Message edited by: Karthikeyan Rajendraprasad ]

Karthikeyan<br />SCJP 1.4, SCWCD.
Nagaraju Nookala

Joined: Mar 19, 2004
Posts: 23
Can you please give me a code snippet?

Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1141

Karthikeyan is saying that the "array" variable is null -- and that's why you are getting a "NullPointerException".

However, I think you do not properly understand how JDBC works. "Array" is not used in the way you are using it in your code (unless there's something I'm missing).

Maybe you should try the JDBC trail in the Java Tutorial

Good Luck,
[ August 12, 2005: Message edited by: Avi Abrami ]
Nagaraju Nookala

Joined: Mar 19, 2004
Posts: 23
I am trying to learn about the interface java.sql.Array. The method getResultSet(long index, int count) is the one I am trying to use in my code. It says "Retrieves a result set holding the elements of the subarray that starts at index index and contains up to count successive elements." As this is an Interface I know I cannot use new operator to initialize this. That is why I want to see if I can get a code snippet. Sorry for not able to express myself properly before.

I agree. Here's the link:
subject: SQL Array Question
It's not a secret anymore!