Results 1 to 6 of 6
Thread: Inserting byte[] into MySQL
- 02-22-2011, 10:37 AM #1
Senior Member
- Join Date
- Mar 2009
- Posts
- 105
- Rep Power
- 0
Inserting byte[] into MySQL
Hi all
I've been working at this for hours and read all sorts of stuff of the web and I just can't seem to figure out how to do this.
I have 2 blob fields in my MySQL table that I'm trying to insert the byte arrays into. When I try to insert it I get an SQL syntax Exception:
This is how I try to insert it:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[B@35d9dc39, [B@72093dcd)' at line 1
Obviously there are some try statements etc. hanging around that I have removed for easy reading and this is just a simple version of what I plan to do as later I'm going to query the DB for the blobs and compare them to inputs but I don't get what I'm doing wrong here with this insert. It looks as though MySQL is having a problem with the contents of the blob. Would a prepared statement make a difference or am I just not handling this byte array properly?Java Code:String sel = "INSERT INTO config.user (name, password) VALUES (" + usrDigest + ", " + pswdDigest + ")"; Statement stmt = conn.createStatement(); stmt.execute(sel);
Just as a bit of background: the byte arrays are the result of SHA-1 digests. I'm trying to make a simple user authorisation system with one-way hashing.
- 02-22-2011, 10:51 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
PreparedStatement see the tutorials.
- 02-22-2011, 10:54 AM #3
Senior Member
- Join Date
- Mar 2009
- Posts
- 105
- Rep Power
- 0
- 02-22-2011, 10:57 AM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Aside from the fact that you never cobble together statements like that (at least values, table names, column names, etc, okay, but not values) it leads to too much trouble to make it worthwhile.
- 02-22-2011, 11:11 AM #5
Senior Member
- Join Date
- Mar 2009
- Posts
- 105
- Rep Power
- 0
- 02-22-2011, 11:51 AM #6
Senior Member
- Join Date
- Mar 2009
- Posts
- 105
- Rep Power
- 0
Similar Threads
-
Check for duplicates before inserting into mySQL table
By igor0203 in forum JDBCReplies: 3Last Post: 12-02-2010, 02:14 PM -
Read a bitmap byte by byte
By cbr400aero in forum Java 2DReplies: 2Last Post: 10-18-2010, 11:42 PM -
Streaming an image byte by byte (and similtaneosly rendering it on screen)
By ea25 in forum New To JavaReplies: 1Last Post: 04-21-2010, 02:28 AM -
Problem regarding Inserting data into Mysql via JSP
By abhi118 in forum JDBCReplies: 5Last Post: 04-05-2010, 01:24 PM -
Problem inserting values to MySQL tables from the Data Source Explorer
By tip in forum EclipseReplies: 0Last Post: 12-24-2007, 09:47 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks