As the title suggests, im trying to upload a file straight to my postgresql database to the data type Bytea with the .setBlob pstm. However JBDC doesnt like it and gives me the following error:
java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc4.Jdbc4PreparedStatement.setBlob(int, InputStream) is not yet implemented.
at org.postgresql.Driver.notImplemented(Driver.java:727)
Ive tried the .setBytes() method but im unsure how to use it correctly with the available data.
Here is the code im using for this:
private void writeToDB(Connection conn, String fileName, InputStream is, String description) throws SQLException {
String sql = "Insert into Attachment(Id,File_Name,File_Data,Description) " //
+ " values (?,?,?,?) ";
PreparedStatement pstm = conn.prepareStatement(sql);
Long id = this.getMaxAttachmentId(conn) + 1;
pstm.setLong(1, id);
pstm.setString(2, fileName);
pstm.setBlob(3, is);
pstm.setString(4, description);
pstm.executeUpdate();
}
Please let me know if there is anything i can do to improve this post, im new to using stackoverflow.
pstm.setBinaryStream(is, theLengthOfTheFile).Attachment.file_dataisn't actually of typebyteabut instead it's abit. Sounds like your table definition forAttachmentis wrong, but we can't know for sure because you haven't disclosed it.setBinaryStream(). This will just read the stream untilend-of-fileis reached.