Here the prepared statement is supposed to insert a line of data from a CSV file into a database row using arrays. The problem is that the lines from the CSV file change a lot so I end up with the array out of bounds error since the prepared statement may call an array index that the line reader does not have.
I've tried different prepared statement methods but none can help here
Path p = Paths.get("ppMonthly.csv");
BufferedReader b;
b = Files.newBufferedReader(p);
String line = "";
while((line = b.readLine()) !=null){
line = b.readLine();
String [] tokens = line.split(",");
PreparedStatement pstm = connection.prepareStatement("INSERT INTO PropertyPrice (SaleID,Price,Date,Post,Property,OldNew,Duration,PAON,SAON,Street,Locality,TownCity,District,County,PPD,Records) " +
"VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);");
pstm.set(1, tokens.length);
pstm.setString(2, tokens[1]);
pstm.setString(3, tokens[2]);
pstm.setString(4, tokens[3]);
pstm.setString(5, tokens[4]);
pstm.setString(6, tokens[5]);
pstm.setString(7, tokens[6]);
pstm.setString(8, tokens[7]);
pstm.setString(9, tokens[8]);
pstm.setString(10, tokens[9]);
pstm.setString(11, tokens[10]);
pstm.setString(12, tokens[11]);
pstm.setString(13, tokens[12]);
pstm.setString(14, tokens[13]);
pstm.setString(15, tokens[14]);
pstm.setString(16, tokens[16]);
java.lang.ArrayIndexOutOfBoundsException: 16