I'm trying to persist an InputStream
representing an image in Oracle database as below:
Connection conn = null;
String message = null;
try {
// connects to the database
Class.forName("oracle.jdbc.driver.OracleDriver");
conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","great123");
String sql = "INSERT INTO contacts (first_name, last_name, photo) values (?, ?, ?)";
PreparedStatement statement = conn.prepareStatement(sql);
statement.setString(1, firstName);
statement.setString(2, lastName);
if (inputStream != null) {
column
statement.setBlob(3, inputStream);
}
int row = statement.executeUpdate();
if (row > 0) {
message = "File uploaded and saved into database";
}
} finally {
if (conn != null) {
// closes the database connection
try {
conn.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
However, it throws the below exception:
console output: Servlet.service() for servlet [com.sandy.FileUploadDBServlet] in context with path [/TestAgent] threw exception [Servlet execution threw an exception] with root cause java.lang.AbstractMethodError: oracle.jdbc.driver.OraclePreparedStatementWrapper.setBinaryStream(ILjava/io/InputStream;)
I have tried statement.setBlob(3, inputStream);
as well as statement.setBinary(3, inputStream);
, but no go.