Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loading images into MySQL via Ant

 
Min Huang
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Min Huang
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic