Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL Array Question

 
Nagaraju Nookala
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
array is not initialized.
[ August 12, 2005: Message edited by: Karthikeyan Rajendraprasad ]
 
Nagaraju Nookala
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please give me a code snippet?

Thanks
Nookala
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic