java 将 T4CConnection 转换为 OracleConnection 时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27281407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error casting T4CConnection to OracleConnection
提问by Gurkha
Spring application using JNDI lookup to get datasource as following:
Spring 应用程序使用 JNDI 查找来获取数据源,如下所示:
@Bean(name = "dataSource1", destroyMethod = StringUtils.EMPTY)
public DataSource dataSource() {
final JndiDataSourceLookup lookup = new JndiDataSourceLookup();
lookup.setResourceRef(true);
return lookup.getDataSource(this.environment.getProperty(Constants.DB_JNDI_NAME_ES));
}
and getting a connection from the datasource as follows :
并从数据源获取连接如下:
@Autowired
@Qualifier("dataSource1")
private DataSource ds;
Connection conn = null;
conn = this.ds.getConnection();
But when i pass that connection to StructDescriptor it throws classCastException as follows:
但是当我将该连接传递给 StructDescriptor 时,它会抛出 classCastException 如下:
StructDescriptor desc1 = StructDescriptor.createDescriptor("MSAF_DBA.AMOUNT_DUE_OBJ",conn);
StructDescriptor desc1 = StructDescriptor.createDescriptor("MSAF_DBA.AMOUNT_DUE_OBJ",conn);
java.lang.ClassCastException: weblogic.jdbc.wrapper.PoolConnection_oracle_jdbc_driver_T4CConnection cannot be cast to oracle.jdbc.OracleConnection
at oracle.sql.StructDescriptor.createDescriptor(StructDescriptor.java:101)
at oracle.sql.StructDescriptor.createDescriptor(StructDescriptor.java:72)
at com.ceiwc.es.policyholder.dao.PolicyHolderDaoImpl.getAmountDue(PolicyHolderDaoImpl.java:290)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
My understanding is the getConnection()
returns a T4CConnection
where as OracleConnection
is required. Tried couple of ways to get the oracleConnection
but cant seem to get it. Any help would be appreciated.
我的理解是getConnection()
回报T4CConnection
,其中的OracleConnection
是必需的。尝试了几种方法来获得oracleConnection
但似乎无法获得它。任何帮助,将不胜感激。
采纳答案by Display Name is missing
I believe this has to do with the contents of your war/ear file. Do not package in the Oracle driver .jar file.
我相信这与您的 war/ear 文件的内容有关。请勿打包在 Oracle 驱动程序 .jar 文件中。
Specifically, if you have ojdbc6.jar
in your war file (or the equivalent) it will cause conflicts. It is fine to use that jar for compilation but you won't want it in your classpath as it is already in the Weblogic classpath by default.
具体来说,如果您ojdbc6.jar
的 war 文件(或等效文件)中有它会导致冲突。可以使用该 jar 进行编译,但您不希望在类路径中使用它,因为默认情况下它已经在 Weblogic 类路径中。