我在 Tomcat 中使用基于 Java 的 Web 应用程序。我通过以下方式将我的应用程序与 Oracle 连接起来:
<Resource name="jdbc/conn" auth="Container" type="oracle.jdbc.pool.OracleDataSource" driverClassName="oracle.jdbc.driver.OracleDriver" factory="oracle.jdbc.pool.OracleDataSourceFactory" url="jdbc:oracle:thin:@XXX.XXX.XXX.XXX:1521:XE" user="XXX" password="XXX" maxActive="100" maxIdle="30" maxWait="10000" scope="Shareable"/>
我尝试对 SQLServer 做同样的事情:
<Resource name="jdbc/conn" auth="Container" type="com.microsoft.sqlserver.jdbc.SQLServerDataSource" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" factory="com.microsoft.sqlserver.jdbc.SQLServerDataSourceObjectFactory" url="jdbc:sqlserver://XXX.XXX.XXX.XXX:1433;databaseName=XXX" username="XXX" password="XXX" maxActive="100" maxIdle="30" maxWait="10000"/>
但这行不通!
我知道我可以使用 type="javax.sql.DataSource" 来管理这两种情况,但我需要在 OracleDataSource 和 SQLServerDataSource 中转换数据源...这是 java 代码:
Context ctx = new InitialContext();
Object obj = ctx.lookup("java:comp/env/jdbc/conn");
我收到此异常:
Unexpected exception resolving reference
com.microsoft.sqlserver.jdbc.SQLServerException: Riferimento DataSource non valido.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:171)
at com.microsoft.sqlserver.jdbc.SQLServerDataSourceObjectFactory.getObjectInstance(SQLServerDataSourceObjectFactory.java:37)
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:140)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
at org.apache.naming.NamingContext.lookup(NamingContext.java:793)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
拜托,你能帮帮我吗?