Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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
 
it's a teeny, tiny, wafer thin ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic