I cannot reproduce the error with simple valid input. Check your input for lines with fewer than four columns especially the last/blank lines: your code assumes at least four columns in the input. Run the program in a debugger and determine where the error is originating.
You should not build SQL statements as strings; they are prone to error, open to exploitation, and hard to maintain. Prepare a query and using bindValue() (See Approaches to Binding Values.
Bookmarks