I have the following code using oracle.sql.BLOB
BLOB b = BLOB.createTemporary(conn, false, BLOB.DURATION_SESSION);
//conn is a PostgreSQL connection (java.sql.Connection object)
b.setBytes(1, someString.getBytes());
ps.setBlob(++i, b); //ps is a PreparedStatement
Obviously it wouldn't work because createTemporary
expects an Oracle connection.
What is the equivalent way of achieving this using a Postgres connection? I understand the Postgres equivalent of Blob is ByteA. The target column is a
bytea
column. Can I just do the following? Or is there a proper way of achieving the same effect?ps.setBytes(++i, someString.getBytes());
Also, how do I make the Oracle-specific code DB-vendor-independent? (avoiding the use of
oracle.sql.BLOB
even if it is an Oracle connection)