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)




Recommended Answers

All 4 Replies

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.

Which line is the exception thrown from?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.