File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes SQL Array Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL Array Question" Watch "SQL Array Question" New topic
Author

SQL Array Question

Nagaraju Nookala
Greenhorn

Joined: Mar 19, 2004
Posts: 23
Hi,

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;

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

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

//resultSet.close();

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

resultSet = array.getResultSet(index, count);

while(resultSet.next()){
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.

Nookala
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
Greenhorn

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

Thanks
Nookala
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

Nookala,
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,
Avi.
[ August 12, 2005: Message edited by: Avi Abrami ]
Nagaraju Nookala
Greenhorn

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.

Thanks,
Nookala.
 
Don't get me started about those stupid light bulbs.
 
subject: SQL Array Question