ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guy Rouillier <guyr-...@burntmail.com>
Subject Re: oracle.sql.STRUCT cannot be cast to oracle.sql.STRUCT
Date Tue, 27 Apr 2010 17:22:25 GMT
Here is the example from the site:


        1. ......
        2. Statement stmt = connection.createStatement();
        3. ResultSet rs= stmt.executeQuery("SELECT * FROM emp_table");
        4. if(rs.next()) {
        5.   java.sql.Struct empType = (java.sql.Struct)rs.getObject(1);
        6.   System.out.println("Number of attributes "+ 
empType.getAttributes().length);
        7.   System.out.println("Name is " + empType.getAttributes()[0]);
        8.   System.out.println("Designation is " + 
empType.getAttributes()[1]);
        9.   System.out.println("Department is " + 
empType.getAttributes()[2]);
       10. }
       11. stmt.close();
       12. ......



On 4/27/2010 7:15 AM, Brian May wrote:
> I would be happy to use a different method if it will be easier,but I
> can not access that link. I am told it is only available to
> ParnerNetwork Program Partners.
>
> Thanks
>
>
> Guy Rouillier wrote:
>> I've never had the need to use Oracle struct datatype, but I just used
>> Google to find this:
>>
>> http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/objects/ObjectTypes.html
>>
>>
>> The example is doing things differently than your code is. Perhaps
>> following the example will produce useful results.
>>
>> This appears to be a JDBC issue rather than an iBATIS issue.
>>
>> On 4/26/2010 2:27 PM, Brian May wrote:
>>> I am trying to map an Oracle type to a Java object using ibatis, but I
>>> am confounded by a ClassCastException. It seems like I am using the
>>> wrong version of the oracle.sql.STRUCT object, but I have no idea how to
>>> find out what version of I should be using. I currently have Ibatis
>>> 2.3.4, ojdbc6, and Spring 3.0.2. Any help would be appreciated.
>>>
>>> SqlMap:
>>> <resultMap class="Object" id="attributeMap">
>>> <result property="attribute" javaType="Object" jdbcType="ARRAY"
>>> typeHandler="AttributeHandlerCallback"/>
>>> </resultMap>
>>>
>>> <select id="attribute" resultMap="attributeMap">
>>> select
>>> attribute_obj(0)
>>> from dual
>>> </select>
>>>
>>> Dao:
>>> public void getAttribute() {
>>> queryForObject("attribute");
>>> )
>>>
>>> TypeHandler:
>>> @Override
>>> public Object getResult(final ResultGetter resultGetter) throws
>>> SQLException {
>>> Attribute atttribute = new attribute();
>>> try {
>>> final Object object = resultGetter.getObject();
>>> System.out.println(object.getClass());
>>> final STRUCT array = (oracle.sql.STRUCT)resultGetter.getObject();
>>> } catch (SQLException e) {
>>> // TODO: handle exception
>>> e.printStackTrace();
>>> }
>>>
>>> return attribute
>>> }
>>>
>>> Caused by: java.lang.ClassCastException: oracle.sql.STRUCT cannot be
>>> cast to oracle.sql.STRUCT
>>> at
>>> gov.noaa.ncdc.cdo.services.dao.ibatis.typehandlers.AttributeHandlerCallback.getResult(DataHandlerCallback.java:30)
>>>
>>>
>>> at
>>> com.ibatis.sqlmap.engine.type.CustomTypeHandler.getResult(CustomTypeHandler.java:58)
>>>
>>>
>>> at
>>> com.ibatis.sqlmap.engine.mapping.result.ResultMap.getPrimitiveResultMappingValue(ResultMap.java:617)
>>>
>>>
>>> at
>>> com.ibatis.sqlmap.engine.mapping.result.ResultMap.getResults(ResultMap.java:345)
>>>
>>>
>>> at
>>> com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:384)
>>>
>>>
>>> at
>>> com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:300)
>>>
>>>
>>> at
>>> com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:189)
>>>
>>>
>>> at
>>> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221)
>>>
>>>
>>> at
>>> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
>>>
>>>
>>> ... 46 more
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>>
>>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>


-- 
Guy Rouillier

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Mime
View raw message