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 1107017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:52:38+00:00 2026-05-17T01:52:38+00:00

I have been trying to set up a DatabaseConnectionPool for a web app for

  • 0

I have been trying to set up a DatabaseConnectionPool for a web app for the last couple of days with no success. I have read the relevant sections of the Tomcat docs and a great deal around the subject and think I’m doing everything right, but obviously not because I keep on getting the following error:

Cannot create PoolableConnectionFactory (Access denied for user ''@'localhost' (using password: YES))

I’m not getting the error when I start Tomcat running, but when I try to run the following servlet:

package twittersearch.web;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import twittersearch.model.*;
public class ConPoolTest extends HttpServlet {

    public void doGet(HttpServletRequest request,
                  HttpServletResponse response) 
                  throws IOException, ServletException {
        Context ctx = null;
        DataSource ds = null;
        Connection conn = null;
        try {
            ctx = new InitialContext();
            ds = (DataSource)ctx.lookup("java:comp/env/jdbc/twittersearchdb");
            conn = ds.getConnection();
            if(conn != null) {
                System.out.println("have a connection from the pool");
            }
        } catch(SQLException e) {
            e.printStackTrace();
        } catch(NamingException e) {
            e.printStackTrace();
        } finally {
            try {
                if(conn!=null) {
                    conn.close();
                }
            } catch(SQLException e) {
                e.printStackTrace();
            }
        }
    }
}

The context for the webapp is:

<?xml version='1.0' encoding='utf-8'?>
<Context>

    <!-- Configure a JDBC DataSource for the user database -->
 <Resource name="jdbc/twittersearchdb" 
           type="javax.sql.DataSource" 
     auth="Container" 
     user="root" 
     password="mypwd" 
     driverClassName="com.mysql.jdbc.Driver" 
     url="jdbc:mysql://localhost:3306/twitter" 
     maxActive="8" 
     maxIdle="4"/>


</Context>

What I really don’t understand is why the error isn’t saying that the access is denied to ‘root’@’localhost’ when I’ve specified that that’s the user.

What I’ve tried:

Do I have a duplicate context.xml? No. I deleted the default on in Tomcat 6.0/conf. I tried putting a context.xml in [mywebappname]/META-INF/context.xml but not only did this not work, but resulted in the creation of a file named TwitterSearch.xml which was autogenerated and put in the Tomcat 6.0/conf/Catalina/localhost directory. So now I’m just editing that one and thats the only one I have.

Is it the version of Tomcat? Well, I completely reinstalled the latest version of Tomcat 6.0 so I don’t think it’s that.

Are we missing some jars? I have the tomcat-dbcp.jar, jconnector.jar and all the other ones that I think I’m meant to have in the Tomcat 6.0/lib directory.

When I look at the passwords in the MySQL database they seem to have been coded for security purposes into a long alpha-numeric string. Is this normal? Should I have this in my context.xml or just the normal password?

I really don’t know how I can sort this out and would really appreciate some expert advice.

Many thanks in advance.

Joe

  • 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-05-17T01:52:39+00:00Added an answer on May 17, 2026 at 1:52 am

    Your setup looks fine. This looks to purly be a permissions problem.

    You need to grant that user access in mysql. While Java will connect to localhost, it will do so using tcp/ip – however in mysql localhost and 127.0.0.1 have different meaning. Issuing this SQL should do the trick.

    grant all on twitter.* to 'root'@'127.0.0.1' identified by 'mypwd';
    

    That assumes Java resolves ‘localhost’ to 127.0.0.1, if things still doesn’t work, you could try changing your connection string to “jdbc:mysql://127.0.0.1:3306/twitter”

    Should I have this in my context.xml
    or just the normal password?

    As you have it now, the plaintext password.

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

Sidebar

Related Questions

for around 5 consecutive days i have been trying to set up my computer
I have been trying to set up Titanium and Android for 3 days. Still
I have been trying to set up OpenCV for the past few days with
I have been trying to set up the following script without success. I have
have been trying couple of hours now to make my iphone app universal. The
I have been trying to set up TeamCity 6.5 as a WAR under Tomcat
I have been trying for last 3 days still i am not able to
Basically have been trying to set the wallpaper through a location based app. WallpaperManager
I have been trying to set up Eclipse and the Arduino libraries. I have
I have been trying to set the scroll of my page to a certain

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.