Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7892913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:59:12+00:00 2026-06-03T06:59:12+00:00

Been pulling my hair trying to set up a data source in in Tomcat

  • 0

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

  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
    }
    

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”

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:59:13+00:00Added an answer on June 3, 2026 at 6:59 am

    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.

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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been pulling my hair out trying to get some data to come across
I have been pulling my hair trying to figure this out but nothing is
Ive been pulling my hair out trying to figure out how to embed a
I've been pulling my hair out trying to use jQuery.get() to pull in my
I have been pulling my hair out trying to figure out what I can't
I have been pulling my hair out trying to make this work. I have
i've been pulling my hair over this a few days, I'm trying to setup
I've been pulling my hair out this morning trying to figure this out. I
So i've been pulling my hair out trying to install the mysqldb package. When
Have been pulling out my hair trying to find out why my sessions are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.