setting RAW datatype through prepared statement

2019-06-23 22:45发布

问题:

I have a column in the table column name is INSTANCE_GUID its raw data type.

I am writing a prepared statement select query to and setting INSTANCE_GUID

pstatement.setString(instanceGuid);

But is this the right way to set a raw data type.Please let me know how to set the RAW dataType should i use setByte?

Thanks

回答1:

As described in the Oracle JDBC Developer's guide and reference 11g, when using a RAW column, you can treat it as a BINARY or VARBINARY JDBC type, which means you can use the JDBC standard methods getBytes() and setBytes() which returns or accepts a byte[]. setBytes() will accept a long array (> 4000 bytes).

The other options is to use the Oracle driver specific extensions getRAW() (oracle.jdbc.OracleResultSet) and setRAW() (oracle.jdbc.OraclePreparedStatement) which return or accept a oracle.sql.RAW. Using these two will require you to unwrap and/or cast to the specific Oracle implementation class.

To create one, just call new oracle.sql.RAW(byte[]).