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
byteacolumn. 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.BLOBeven if it is an Oracle connection)
BLOBto store aString? That is much better stored in aCLOB(textin Postgres)setBinaryStreambetter thansetBytes? wouldsetBytesbe enough here?setBinaryStream()works with all JDBC drivers, whereas some drivers do not supportsetBytes(). If you know exactly which drivers you'll be using and those supportsetBytes()as well, there is nothing wrong with it.