无法从Tomcat 6连接到Oracle 12c:没有匹配的身份验证协议(ORA-28040)

时间:2014-02-10 15:56:57

标签: java-ee database-connection tomcat6 oracle12c

我必须从Tomcat 6连接到Oracle 12c数据库。我创建了一个servlet,用于创建与此数据源的连接(来自META-INF/context.xml):

<Context debug="0" docBase="/Test" path="/" reloadable="true">
   <Resource
      name="jdbc/test" auth="Container" type="javax.sql.DataSource"
      driverClassName="oracle.jdbc.OracleDriver"
      url="jdbc:oracle:thin:@somewhere:someport:someservice"
      username="someuser" password="somepass" maxActive="10" maxIdle="5"
      maxWait="5000" removeAbandoned="true" removeAbandonedTimeout="60"
      logAbandoned="true"
   />
</Context>

使用此代码创建连接时:

InitialContext initContext = new InitialContext();
Context ctx = (Context) initContext.lookup("java:comp/env");
DataSource ds = (DataSource) ctx.lookup("jdbc/test");
conn = ds.getConnection();

我得到以下异常:

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (ORA-28040: No matching authentication protocol
)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
    at tomcattest.TestIt.doPost(TestIt.java:48)
    at tomcattest.TestIt.doGet(TestIt.java:27)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.sql.SQLException: ORA-28040: No matching authentication protocol

    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:283)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:278)
    at oracle.jdbc.driver.T4CTTIoauthenticate.receiveOsesskey(T4CTTIoauthenticate.java:294)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:357)
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:441)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
    at org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
    at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
    ... 18 more

但是使用此代码创建连接

Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@somewhere:someport:someservice", "someuser", "somepass");

工作正常;此外,如果我在servlet中使用URL到Oracle 11g数据库,它就可以工作。

我正在为Oracle 12c,Tomcat 6,Java 1.6,Windows 7使用ojdbc6.jar驱动程序。任何人都有一些提示吗?

3 个答案:

答案 0 :(得分:2)

您可能已在服务器上的sql.net ora文件中设置了SQLNET.ALLOWED_LOGON_VERSION。

答案 1 :(得分:0)

我决定搬到Tomcat 7。

答案 2 :(得分:0)

适用于我,但使用参数 SQLNET.ALLOWED_LOGON_VERSION_SERVER

我将它设置为8以确定。

请参阅文档:http://docs.oracle.com/database/121/NETRF/sqlnet.htm#NETRF2016