I have implemented java.sql.SQLData
in order to bind UDT objects to prepared statements using ojdbc6. Now, some of my UDT's contain arrays. What I need to do now is this:
class MyType implements SQLData {
public void writeSQL(SQLOutput stream) throws SQLException {
Array array = //...
stream.writeArray(array);
}
}
In order to construct Oracle arrays, I need a JDBC Connection. Typically, this is done as such:
OracleConnection conn = // ...
Array array = conn.createARRAY("MY_ARRAY_TYPE", new Integer[] { 1, 2, 3 });
However, in that writeSQL(SQLOutput)
method, I do not have a connection. Also, for reasons that are hard to explain in a concise question, I cannot maintain a connection reference in MyType
. Can I somehow extract that connection from SQLOutput
? I'd like to avoid using instable constructs like this:
// In ojdbc6, I have observed a private "conn" member in OracleSQLOutput:
Field field = stream.getClass().getDeclaredField("conn");
field.setAccessible(true);
OracleConnection conn = (OracleConnection) field.get(stream);
Any ideas? Alternatives?
ThreadLocal
before binding the UDT. That would work, but it feels really wrong... – Agent