| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.misc -> JDBC getObject() and Oracle Object Types
I'm having problems retrieving Oracle object types from the database
through JDBC. The Oracle object type is called SCHEMANAME.T_TEST_OBJ
and it maps to the Java class com.carrierpoint.db.TestClass. Although
the stored procedure that gets the object seems to succeed, the call
to getObject to get the result fails. Here's the relevent code:
public TestClass getTestObject(Long id)
{
Connection dbConn = null;
try
{
dbConn = <blah> // get the connection, set up mapping etc.
// Print out the type map for debugging purposes.
Map typeMap = dbConn.getTypeMap();
for (Iterator i = typeMap.keySet().iterator(); i.hasNext(); )
{
Object key = i.next();
CPTrace.traceMessage("Key: " + key + ", "
+ "Value: " + typeMap.get(key));
}
// Setup the call
String sql = "{?=call object_test_package.cp_get_test_obj(?)}";
CallableStatement call = dbConn.prepareCall(sql);
call.registerOutParameter(1,
OracleTypes.STRUCT,
"SCHEMANAME.T_TEST_OBJ");
call.setLong(2, id.longValue());
// Do it
call.execute();
// This will fail.
return (TestClass) call.getObject(1);
} catch (SQLException e)
{
e.printStackTrace();
} finally
{
// Clean up.
}
}
The output is:
Key: SCHEMANAME.T_TEST_OBJ, Value: class com.carrierpoint.db.TestClass java.sql.SQLException: Inconsistent java and sql object types: SCHEMANAME.T_TEST_OBJ
at java.lang.Throwable.fillInStackTrace(Native Method)
at java.lang.Throwable.fillInStackTrace(Compiled Code)
at java.lang.Throwable.<init>(Compiled Code)
at java.lang.Exception.<init>(Compiled Code)
at java.sql.SQLException.<init>(SQLException.java:43)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:114)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:156)
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:775)
at oracle.sql.STRUCT.toClass(STRUCT.java:443)
at oracle.sql.STRUCT.toJdbc(STRUCT.java:378)
at oracle.jdbc.driver.OracleStatement.getObjectValue(Compiled
Code)
at oracle.jdbc.driver.OracleStatement.getObjectValue(Compiled
Code)
at oracle.jdbc.driver.OracleCallableStatement.getObject(Compiled
Code)
(...)
I am able to successfully write the object in the database through the custom Java class with another stored procedure. In addition, I have traces in the getSQLTypeName, readSQL, and writeSQL methods of my class, and none of them are traced before the above exception is thrown (they are traced when the object is written to the database, though).
Any help would be greatly appreciated.
--Steven Received on Wed Sep 26 2001 - 16:45:13 CDT
![]() |
![]() |