本文介绍了如何将NewProxyConnection转换为AS400JDBCConnection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Spring的新手.我在Spring中使用ComboPooledDataSource进行连接池.我正在使用AS400进行连接.我的问题是,当我使用此连接并尝试对此类型进行铸造时AS400JDBCConnection as400Conn =(AS400JDBCConnection)conn;它提供了ClassCastCastException,因为ComboPooledDataSource返回的连接对象的类型为NewProxyConnection,如何将其转换为AS400JDBCConnection.

I am new to Spring . I am using ComboPooledDataSource for connection pooling in Spring.I am using the AS400 for making the connection.My problem is that when I am using this connection and try to typecast thisAS400JDBCConnection as400Conn = (AS400JDBCConnection)conn;It gives the ClassCastCastException because the connection object returned by the ComboPooledDataSource is of type NewProxyConnection how can I typecast it into AS400JDBCConnection.

推荐答案

Spring确实支持展开代理的ComboPooledDataSource对象.如果使用的是JdbcTemplate,则可以将nativeJdbcExtractor属性设置为适当的对象.因此,您可以在任何地方检索本机Connection,甚至任何派生对象(如ResultSet)都将是本机的.

Spring does support unwrapping the proxied ComboPooledDataSource object. If you are using JdbcTemplate, you can set the nativeJdbcExtractor property to an appropriate object. So any place you can retrieve a native Connection or even any of the derived objects (like ResultSet) will be native.

NativeJdbcExtractor接口的JavaDoc,以获取受支持的类的列表.这样可以帮助您确定哪种实现适合您的应用程序.

The JavaDoc for the NativeJdbcExtractor interface for a list of supported classes. That can help you decide which implementation works for you application.

这篇关于如何将NewProxyConnection转换为AS400JDBCConnection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 09:22