0

thank you for any input. I am getting the below error message. I am running JDBC with postgresql and attempting to run 9 queries on my query.txt file that I have. The tables were created and values inserted according to the console message below. However, I am getting exception in the thread main. I am not understanding how to clear this and have my console run successfully and my 1.html file execute my query results. Again thank you all for your help on this. Here is my code for the specific class where I am running my queries.

package dbms.vt;
import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;

public class SQLRunner {

public static boolean execute(Connection connection, String fileURL)
throws SQLException, IOException {



ArrayList<String> tableList = new ArrayList<String>();

Statement stmt = connection.createStatement() ;

try{

tableList = FileIO.readStatementsFromFile(fileURL);

System.out.println(tableList.get(9));

}

catch(IOException ex){

System.out.println("IO Exception from SQLRunner");

}

String testStmt = tableList.get(9);

stmt.executeUpdate(testStmt);
stmt.close();

return true;

}

}

Here is the console results:

SET client_encoding = 'UTF8';

Successfully created all tables.

COMMIT; 

Successfully inserted all values.

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 9, Size: 
9
    at java.util.ArrayList.rangeCheck(ArrayList.java:653)
    at java.util.ArrayList.get(ArrayList.java:429)
    at dbms.vt.SQLRunner.execute(SQLRunner.java:21)
    at dbms.vt.MyJDBC.main(MyJDBC.java:27)
AMMOTECH
  • 21
  • 6
  • `tableList` size is 9 --> Valid indexes for `get()` method are 0-8. – jlordo Mar 05 '17 at 23:38
  • Thank you for the reply jlordo. I agree with your feedback. However, I have a total of 10 queries and still getting the same error message. – AMMOTECH Mar 05 '17 at 23:48
  • 1
    You might have 10 queries but still my comment is correct. The code fails at line 21 of SQLRunner.java (as per the given stacktrace) . That is `String testStmt = tableList.get(9);` Also, the error message says that the list has a length of 9 (thus my previous comment: valid indexes are 0-8. You are passing 9). For debugging, look into the list and see if it contains what you expect. – jlordo Mar 06 '17 at 00:01

0 Answers0