It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes Problem Storing image file in MySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Problem Storing image file in MySQL" Watch "Problem Storing image file in MySQL" New topic

Problem Storing image file in MySQL

Scott Updike
Ranch Hand

Joined: Feb 16, 2006
Posts: 92
I'm attempting to write a procedure to take a .gif file and store it in my MySQL database. So, in order, this is what happens:
1) user selects which file to save.
2) I take that file selection, store it locally on the web server.
3) Create a FileInputStream object based on the File object in (2).
4) Call my DAO with the FileInputStream where I insert the gif file using the PreparedStatement.setBinaryStream method.

When I run this code (below), I get the following error:
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 '(inv_id, caption, inv_image) values (63,'test',_binary'����\0JFIF\0\0\0d\0d\0' at line 1

Code snippets are below:

This code snippet takes the request object and parses out the parameters for the DAO call (one of which is the file itself).

Here's the code in my DAO:

I can verify that the file is valid and stored properly locally on the web server, so I know the chained File to the FileInputStream object is valid and is not null.

Here's the table that I'm writing to:

My MySQL Connector is version 3.1.12.

Does anyone have any ideas?

I agree. Here's the link:
subject: Problem Storing image file in MySQL
It's not a secret anymore!