Sometimes you need to access vendor specific JDBC methods that differ from the standard JDBC API. This can be problematic if you are running in an application server or with a DataSource
that wraps the Connection
, Statement
and ResultSet
objects with its own wrapper objects. To gain access to the native objects you can configure yourJdbcTemplate
or OracleLobHandler
with a NativeJdbcExtractor
.
翻译:
有时候,你需要访问特定于供应商的JDBC方法不同于标准JDBC API。这可能会出现问题,如果你正在运行一个应用程序服务器或一个DataSource包装的连接,Statement和ResultSet对象与自己的包装对象。要获得本地对象,你可以配置你JdbcTemplate或OracleLobHandler的一个NativeJdbcExtractor。
The NativeJdbcExtractor
comes in a variety of flavors to match your execution environment:
-
SimpleNativeJdbcExtractor
-
C3P0NativeJdbcExtractor
-
CommonsDbcpNativeJdbcExtractor
-
JBossNativeJdbcExtractor
-
WebLogicNativeJdbcExtractor
-
WebSphereNativeJdbcExtractor
-
XAPoolNativeJdbcExtractor
Usually the SimpleNativeJdbcExtractor
is sufficient for unwrapping a Connection
object in most environments. See the Javadocs for more details.
spring 配置文件如下:
<!-- nativeJdbcExtractor 和 oracleLobHandler Bean 都设置为 lazy-init="true",这是因为 -->
<!-- nativeJdbcExtractor 需要通过运行期的反射机制获取底层的 JDBC 对象, -->
<!-- 所以需要避免在 Spring 容器启动时就实例化这两个Bean。 -->
<bean id="nativeJdbcExtractor"class="org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor" lazy-init="true" />
<bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init="true">
<property name="nativeJdbcExtractor" ref="nativeJdbcExtractor"></property>
</bean>
<!-- 我的实现类,因为我用的是C3P0 连接池方式,配置的nativejdbcextractor是C3P0 。 -->
<bean id="simpleWriterBlob" class="com.ww.jdbc.writer.blob.SimpleWriterBlob">
<property name="dataSource" ref="dataSource"></property>
<property name="lobHandler" ref="oracleLobHandler"></property>
</bean>