0

Is it possible to use the mysql command LOAD DATA INFILE as PreparedStatement? Because java seems to interpret the ? placeholder as filename itself.

Statement st = con.prepareStatement("LOAD DATA LOCAL INFILE '?'...");

for (file : files) {
  st.setString(1, file.getAbsolutePath()); 
  st.addBatch();
}
st.executeBatch();

Result:

java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964) ~[mysql-connector-java-5.1.41.jar:5.1.41]
membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • 1
    It is not possible as i know – Jens May 10 '17 at 13:06
  • @Jens is it alternatively possible to "collect" the prepared statements for `LOAD DATA INFILE`, so that I can send multiple prepared infile statements at once using `executeBatch()` or similar? – membersound May 10 '17 at 13:23
  • prepared Statements with `LOAD DATA INFILE` makes no sence. but you can use "normal" Statements for that: http://viralpatel.net/blogs/batch-insert-in-java-jdbc/ – Jens May 10 '17 at 13:27

0 Answers0