0

Hi to all, Im going through JDBC currently, I got struck with Java.lang.ArrayIndexOutofBounds Exception:0. I'm not getting the solution to this exception. Please help me to solve this exception, thanks in advance.

import java.sql.*;

class Select
{
    public static void main(String args[])
    {
      try
      {
        Class.forName("jdbc.oracle.driver.OracleDriver");
        Connection con = DriverManager.getConnection
        ("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
        Statement stmt = con.createStatement();
        ResultSet rs=stmt.executeQuery("select * from Student");
        ResultSetMetaData rm = rs.getMetaData();
        int n =rm.getColumnCount();
        for(int i =1; i<=n; i++)
        {
            System.out.print(rm.getColumnName(i)+"\t");

        }
        System.out.println();

        while(rs.next())
        {
            System.out.print(rs.getInt("rno")+"\t");
            System.out.print(rs.getString("name")+"\t");
            System.out.print(rs.getInt("marks"));

        }

      }


      catch(Exception e)
      {
        System.out.println(e);

      }

    }

}

Edited by Ealiom

3
Contributors
4
Replies
20
Views
2 Years
Discussion Span
Last Post by JamesCherrill
0

Are you sure rm actually has rows? You're not checking for that and then trying to access the element at position 1. If there is no element at position 1 you would see this error.

0

Thanks for the reply, resultset pointer points to before first record whenever resultset is generated.

0

Yes, that's what the API doc says...

A ResultSet object maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row.

Now give us the details of your array index exception if you want any help

Edited by JamesCherrill

This article has been dead for over six months. Start a new discussion instead.
Be sure to adhere to our posting rules.