I\'m trying to insert an image into database and with auto increment photo_id.
my table columns are:
PHOTO_ID (primary key),
USERNAME (fkey),
PICTURE,
InputStream.available()
does not return the size of the stream (which is clearly documented in the Javadocs).
You will need to query the size of the file, not the "available bytes" in the inputstream:
ps.setBinaryStream(2, fis, (int)file.length());
depending on the version of your JDBC driver you can also use
ps.setBinaryStream(2, fis, file.length());
But setBinaryStream(int, InputStream, long)
is defined in JDBC 4.0 and thus not implemented by all driver versions. setBinaryStream(int, InputStream, int)
is JDBC 2.0 (if I'm not mistaken) and should be available in all versions.