Thomas Kwan wrote:
> Michael Widenius wrote:
> > >>>>> "Thomas" == Thomas Kwan <thomask@stripped>
> > Thomas> I want to add a stream of binary data (a jpeg file) via
> > Thomas> SQL insert command. What format do I need to use when inserting the
> > Thomas> binary data?
> > Thomas> thanks
> > Hi!
> > The MySQL manual tells you which characters you should escape.
> > Manual section: 'Literals: how to write strings and numbers'
> The manual talked about special characters (i.e. \,NULL,...etc). But
> it did not talk about unprintable character like 0x1, 0x2,...
> I am using Java, and byte array (i.e. byte) is what I have. Should
> I just do the following:
> byte jpgPic = ...
> String picStr = new String(jpgPic);
> dataStr = escapeSpecial(picStr);
> s.executeUpdate("INSERT ... (" + dataStr + ")");
> > Most MySQL API:s has also a function to escape a string
> > (mysql_escape_string in C or the quote in perl).
> > Which language are you using?
> > Regards,
> > Monty
Just use the java.sql.PreparedStatement.setBytes(...) Method.
All escaping and such stuff is done there automatically.
If you need an example, just mail again.
There is a separate mailinglist for java <-> mysql related stuff: