• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Problem Storing image file in MySQL

 
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?

Thanks,
Scott
 
Can't .... do .... plaid .... So I did this tiny ad instead:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!