• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem Storing image file in MySQL  RSS feed

Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!