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[])
        Connection con = DriverManager.getConnection
        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++)





      catch(Exception e)




Edited 2 Years Ago by Ealiom

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.

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

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 2 Years Ago by JamesCherrill

This article has been dead for over six months. Start a new discussion instead.