List:General Discussion« Previous MessageNext Message »
From:Christian Mack Date:June 9 1999 7:04pm
Subject:Re: binary data
View as plain text  
Thomas Kwan wrote:
> 
> Michael Widenius wrote:
> 
> > >>>>> "Thomas" == Thomas Kwan <thomask@stripped>
> writes:
> >
> > 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 + ")");
>     ...
> 
> thomas
> 
> >
> > 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

Hi Thomas

No!

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.

BTW:
There is a separate mailinglist for java <-> mysql related stuff:
mailto:java@stripped

Tschau
Christian

Thread
binary data(Thomas Kwan)9 Jun
  • binary dataMichael Widenius9 Jun
  • Re: binary dataYing Zhang9 Jun
  • Re: binary data(Thomas Kwan)9 Jun
  • Re: binary dataChristian Mack9 Jun
  • Re: binary dataChristian Mack10 Jun