dbTalk Databases Forums  

byte[] data to mysql

comp.databases comp.databases


Discuss byte[] data to mysql in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
DBArtisan
 
Posts: n/a

Default byte[] data to mysql - 01-15-2007 , 08:08 AM






Hi All,

I have a byte[] array data that i want to insert/update into a table in
mysql.

here is the code:

Connection conn = ....
Statement stmt = conn.createStatement();

String sql = "UPDATE cards SET BlobField = ?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setBytes(1, "hghghfhgf".getBytes());

stmt.executeUpdate(sql);


I have tried to set the table field to longblob, blob, but failed with
error indicating syntax error "?"

Zab


Reply With Quote
  #2  
Old   
toby
 
Posts: n/a

Default Re: byte[] data to mysql - 01-15-2007 , 12:24 PM







DBArtisan wrote:
Quote:
Hi All,

I have a byte[] array data that i want to insert/update into a table in
mysql.

here is the code:

Connection conn = ....
Statement stmt = conn.createStatement();

String sql = "UPDATE cards SET BlobField = ?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setBytes(1, "hghghfhgf".getBytes());
Try passing a string of the form
X'<hexdigits>'
e.g., in your example
X'686768676866686766'


Quote:
stmt.executeUpdate(sql);


I have tried to set the table field to longblob, blob, but failed with
error indicating syntax error "?"

Zab


Reply With Quote
  #3  
Old   
toby
 
Posts: n/a

Default Re: byte[] data to mysql - 01-15-2007 , 12:26 PM




toby wrote:
Quote:
DBArtisan wrote:
Hi All,

I have a byte[] array data that i want to insert/update into a table in
mysql.

here is the code:

Connection conn = ....
Statement stmt = conn.createStatement();

String sql = "UPDATE cards SET BlobField = ?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setBytes(1, "hghghfhgf".getBytes());

Try passing a string of the form
X'<hexdigits>'
e.g., in your example
X'686768676866686766'
Eh, never mind, that can't really help...

Quote:


stmt.executeUpdate(sql);


I have tried to set the table field to longblob, blob, but failed with
error indicating syntax error "?"

Zab


Reply With Quote
  #4  
Old   
greg.fenton
 
Posts: n/a

Default Re: byte[] data to mysql - 01-23-2007 , 10:50 AM




DBArtisan wrote:
Quote:
here is the code:

Connection conn = ....
Statement stmt = conn.createStatement();

String sql = "UPDATE cards SET BlobField = ?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setBytes(1, "hghghfhgf".getBytes());

stmt.executeUpdate(sql);

Shouldn't that be:

pstmt.executeUpdate();


There is nothing tying stmt to the set parameter in pstmt, so
stmt.executeUpdate(sql) causes the stmt to simply pass sql to the
database which has "?" in it...thus the syntax problem.

greg.fenton



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.