2

In the past I was using v5 of mysql-connector-java a lot. During LOAD DATA LOCAL INFILE, I usually set the connection to allow loading data from inmemory as follows:

com.mysql.jdbc.Connection con;
con.setAllowLoadLocalInfile(true);

Lateron it then set the file as inputstream directly for the database statement:

((com.mysql.jdbc.Statement) ps).setLocalInfileInputStream(new ByteArrayInputStream(...))

Now I'm migrating to version 8.0.13 of the connector, that the method does not exist anymore. Moreover, one has to use java.sql.Connection now.

How can I now set the property to allow load data on the connection explicit?

Especially as java.sql.Statement does not have the .setLocalInfileInputStream() method?

The developer guide even mentions that method, but does not tell how to get access to it: https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-implementation-notes.html

membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • Does this answer your question? [Is a "Load DATA" without a file (i.e., in memory) possible for MySQL and Java?](https://stackoverflow.com/questions/3627537/is-a-load-data-without-a-file-i-e-in-memory-possible-for-mysql-and-java) – Alex R Feb 05 '20 at 04:33

4 Answers4

3

This is how works for me:

jdbc:mysql://localhost:3306/tempDB?allowLoadLocalInfile=true

It is working for Mysql8.0.18

Atul
  • 3,043
  • 27
  • 39
2

The preferred method is to set the connection property allowLoadLocalInfile=true in the connection string and then call the method setLocalInfileInputStream(InputStream stream) from a Statement object cast to the interface com.mysql.cj.jdbc.JdbcStatement.

FilipeSilva
  • 356
  • 3
  • 9
  • This worked with mysql-connector-java 8.0.17! Keep in mind you may have to enable it on the server as well, see this SO thread: https://stackoverflow.com/questions/10762239/mysql-enable-load-data-local-infile for my.cnf/my.ini flags – NekoKikoushi Aug 29 '19 at 13:03
1

At the end I switched to mariadb connector, which is a dropin replacement for mysql, but still has the localinfile method.

membersound
  • 81,582
  • 193
  • 585
  • 1,120
1

In case anyone comes looking at this the class needed moved. It is now in com.mysql.cj.jdbc.StatementImpl at least in 8.0.15

samlii
  • 21
  • 1