• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SQL Array Question

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please give me a code snippet?

Thanks
Nookala
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic