oracle 尝试在 Tomcat 6 中创建数据源时出现“ORA-01017:无效的用户名/密码;登录被拒绝”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10404981/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 04:10:02  来源:igfitidea点击:

Getting "ORA-01017: invalid username/password; logon denied" when trying to create a data source in Tomcat 6

oracletomcatservletsdatasourceora-01017

提问by duvo

Been pulling my hair trying to set up a data source in in Tomcat for an application. The steps I've taken are

一直试图在 Tomcat 中为应用程序设置数据源。我采取的步骤是

  1. Create a META-INF/context.xml with the following content

    <Context>
     <Resource name="jdbc/mydb"
      auth="Container"
      type="javax.sql.DataSource"
      driverClassName="oracle.jdbc.OracleDriver"
      url="jdbc:oracle:thin:@gpqa6.myserver.com:1526:gpqa6"
      username="foo"
      password="foobar"
      maxActive="20"
      maxIdle="30"
      maxWait="-1" />           
    </Context>
    
  2. Enter the following text in WEB-INF/web.xml

    <resource-ref>
        <description>Datasource</description>
        <res-ref-name>jdbc/mydb</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
    
  3. Using it in the code

    public class MyServlet extends HttpServlet {
    
      private DataSource ds;             
    
      public void init() {
    
        try {
        Context ctx = new InitialContext();
        ds = (DataSource) ctx.lookup("java:comp/env/jdbc/mydb");
    
        } catch (NamingException e) {           
            e.printStackTrace();
        }
     }
    
      protected void doGet(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException {
        //this is where the exception is thrown
        Connection conn = ds.getConnection(); 
    
        //...do stuff with the connection
    }
    
  1. 使用以下内容创建一个 META-INF/context.xml

    <Context>
     <Resource name="jdbc/mydb"
      auth="Container"
      type="javax.sql.DataSource"
      driverClassName="oracle.jdbc.OracleDriver"
      url="jdbc:oracle:thin:@gpqa6.myserver.com:1526:gpqa6"
      username="foo"
      password="foobar"
      maxActive="20"
      maxIdle="30"
      maxWait="-1" />           
    </Context>
    
  2. 在 WEB-INF/web.xml 中输入以下文本

    <resource-ref>
        <description>Datasource</description>
        <res-ref-name>jdbc/mydb</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
    
  3. 在代码中使用

    public class MyServlet extends HttpServlet {
    
      private DataSource ds;             
    
      public void init() {
    
        try {
        Context ctx = new InitialContext();
        ds = (DataSource) ctx.lookup("java:comp/env/jdbc/mydb");
    
        } catch (NamingException e) {           
            e.printStackTrace();
        }
     }
    
      protected void doGet(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException {
        //this is where the exception is thrown
        Connection conn = ds.getConnection(); 
    
        //...do stuff with the connection
    }
    

But keep on getting the following error

但继续收到以下错误

"Encounter exception during mapping. Error: Cannot create PoolableConnectionFactory (ORA-01017: invalid username/password; logon denied ) org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (ORA-01017: invalid username/password; logon denied"

“在映射过程中遇到异常。错误:无法创建 PoolableConnectionFactory(ORA-01017:无效的用户名/密码;登录被拒绝)org.apache.tomcat.dbcp.dbcp.SQLNestedException:无法创建 PoolableConnectionFactory(ORA-01017:无效的用户名/密码;登录拒绝”

I know that the username and password are correct. Because the following code works

我知道用户名和密码是正确的。因为下面的代码有效

    Class.forName("oracle.jdbc.OracleDriver").newInstance(); 
    conn = DriverManager.getConnection(
    "jdbc:oracle:thin:@gpqa6.myserver.com:1526:gpqa6", "foo", "foobar");

I've even tried to enter an invalid url but still get the same error. What's going on???

我什至尝试输入无效的网址,但仍然出现相同的错误。这是怎么回事???

Also, does Tomcat have some way of testing the data source similar to WebLogic or Glassfish?

另外,Tomcat 是否有一些类似于 WebLogic 或 Glassfish 的测试数据源的方法?

回答by duvo

Now it's working. Seem like after I establish a connection with the following code

现在它正在工作。好像在我用下面的代码建立连接之后

    Class.forName("oracle.jdbc.OracleDriver").newInstance(); 
    conn = DriverManager.getConnection(
    "jdbc:oracle:thin:@gpqa6.myserver.com:1526:gpqa6", "foo", "foobar");

then switching back to using the data source, it's fine. Maybe it's a caching issue?

然后切换回使用数据源,就可以了。也许这是一个缓存问题?

--Update-- It is a caching issue. Ijust have to delete the \conf\Catalina folder.

--更新--这是一个缓存问题。我只需要删除 \conf\Catalina 文件夹。

This link really helped. http://pwu-developer.blogspot.com/2010/02/why-isnt-my-datasource-configuration.html

这个链接真的很有帮助。 http://pwu-developer.blogspot.com/2010/02/why-isnt-my-datasource-configuration.html