Please help how to import text data file in MySql using JDBC application

How I can write method in my JDBC application to execute next command in MySql database:load data local infile 'D:\\01 - Prevoz\\prevoz u javi\\sifarnici\\new_MBREL.txt' into table mbrel fields terminated by ';' lines terminated by '\n';
[278 byte] By [Snezanaa] at [2007-11-27 6:01:42]
# 1

I only see some requirements.

Where exactly are you stucking while writing code accordingly? Don't you know how to open a file? Don't you know how to read this file line by line? Don't you know how to split a String? Don't you know how to map each record into a DTO? Don't you know how to create a connection? Don't you know how to use statements? Don't you know how to execute a statement? Don't you know how to write SQL? Don't you know how to create a SQL table? Please ask specific questions.

In meanwhile you can take some time to read thoroughly the following links, because those contain the answers on the above questions:

http://java.sun.com/docs/books/tutorial/essential/io/

http://java.sun.com/docs/books/tutorial/jdbc/

http://www.google.com/search?q=sql+tutorial

BalusCa at 2007-7-12 16:42:00 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

1) I do not know if there is a way to do this in JDBC, and I am not sure the "load" command is an actual SQL command. Maybe someone else can confirm this for you.

2) The load command you list is functionality available to the mySQL CLI, or command line interface. Instead of JDBC, you may need to use a system execute process, like this:

Runtime runtime = Runtime.getRuntime();

Process process = runtime.exec( stringLoadRequest );

-- read the DOS output if needed

InputStream inputStream = process.getInputStream();

-- read the inputStream

3) Also, you may need to use the older DOS 8.3 filename protocol for folder and file names. Many path readers (especially CLI driven utilities) do not handle the spaces, special symbols, or name lengths over 8 characters that newer GUI software of Windows programs use.

For example, the filename "bumblyburg.process" has 10 letters in the filename, the dot delimiter, and 7 characters in the extension. Older Dos path readers translate this filename as "bumbly~1.pro". If you set a path to the long name, the filename reader does not see it. This applies to all the foldernames in a path as well.

The good news is you can see for yourself how the DOS shell translates it by going to a command shell and doing a directory listing like this: dir /x. The "/x"displays the names in the older format. Unfortunately, you may have to do this for every foldername in your path. Your input file is probably something like this:

'D:\\01-Pre~1\prevoz~1\sifarn~1\new_MB~1.txt'

Hope this helps!

mamgeorgea at 2007-7-12 16:42:00 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
If it is actually a DDL file, then indeed just load it into the DB using the MySQL source command. But don't call them *.txt. And also don't ask in a Java/JDBC forum how to read txt files intented for a SQL database ;)
BalusCa at 2007-7-12 16:42:00 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...