The problem is how you're trying to store data as a blob. You need to use a PreparedStatement
- specifically, with its setBlob()
method:
String mySQL = "INSERT INTO photos (photo) values (?)";
PreparedStatement pStmt = con.prepareStatement(mySQL);
pStmt.setBlob(1, uploadedInputStream);
pStmt.execute();
Edit to add: The reason it isn't working now is because you're concatenating a String
to create your SQL and you're getting the result of InputStream.toString()
which is what you see being stored - it's the default Object.toString()
which is a combination of the class name and hashcode.
And really you should always use PreparedStatement
s. Not only does it make for cleaner code, it handles quoting/escaping for you which is less error prone.