File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Mysql - Load data infile query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of RabbitMQ in Depth this week in the Open Source forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Mysql - Load data infile query" Watch "Mysql - Load data infile query" New topic

Mysql - Load data infile query

Carl John
Ranch Hand

Joined: Jun 14, 2010
Posts: 47

Hi All,

I'm developing a Java swing application with back end Database MySQL . I've a screen to upload my datas to the Database using the Query like


Here the datas are like from January to June. But if i want to skip any month data or to upload only a particular month then how will i modify the above query.

In my database table , the date column is 'SLDATE'.

Any suggestions please.?

Martin Vajsar

Joined: Aug 22, 2010
Posts: 3707

According to the docs, the LOAD DATA statement doesn't have any option to filter rows based on their column values.

If the date column is first in your input file, you might perhaps be able to import a specific month by using the LINES STARTING BY clause and further tweaking, but I'd say such a solution would be too fragile.

Other than this, you'll probably have to load the contents of the file into a temporary table and then use INSERT INTO ... SELECT to select just the desired subset of rows to insert into the target table.
I agree. Here's the link:
subject: Mysql - Load data infile query