aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Loading images into MySQL via Ant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Loading images into MySQL via Ant" Watch "Loading images into MySQL via Ant" New topic
Author

Loading images into MySQL via Ant

Min Huang
Greenhorn

Joined: Sep 21, 2004
Posts: 16
I am trying to load a bunch of images as seed data into MySQL as part of the build process. Currently, I have an image.sql file that contains binary data, which the mysql client tools will happily import into MySQL:



Unfortunately, the ant sql task fails to parse this file correctly because of the binary data and fails. I've tried combinations of keepformat, encoding, and escapeprocessing, but I still can't execute that sql file via ant.

I have a shell script that loads the data, but I'd really like to be able to use ant and not require mysql client tools or cygwin/unix to be able to load data into the database.

Here are my options:
a) Find out a way to make the ant sql task work with binary data
b) Find out a way to load binary data using mysql's load_file with ant. The load_file function requires an absolute path, so I would need some way to only specify relative paths in the sql file and have ant do the rest. I dont think this is even possible.
c) The least attractive option is to have a <exec> task execute the mysql binary with the correct args. But I dont think there's a way to do unix file redirection; it wouldn't work on Windows.

Any suggestions?


SCJP, SCJD, SCBCD, SCWCD
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29283
    
140

Min,
I don't think it is possible to do this with the sql task. Another alternative is to write a Java program that does the load through JDBC. You would be dependent on a mysql driver, but you wouldn't need the mysql client or exec.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Min Huang
Greenhorn

Joined: Sep 21, 2004
Posts: 16
I thought so. I ended up writing a task that read in id's and image file paths from a properties file, then executed a sql update on all of them. Here's the class:



Target def looks like this:



Unfortunately, mysql's load_file only works on the host computer (ie the computer the mysql instance is running on), so this didnt work when I tried running ant load on another database:



[ April 18, 2007: Message edited by: Min Huang ]
[ April 18, 2007: Message edited by: Min Huang ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Loading images into MySQL via Ant
 
Similar Threads
MySQL Error
Why use ANT?
Ant target to create a database in mysql
how to read from a file and execute the lines
Question about ant