我在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)
拜托,你能帮助我吗?