Unable to create PoolableConnectionFactory (access denied for user '@' localhost '

I have been trying to configure DatabaseConnectionPool for a web application for the past few days without success. I have read the relevant sections of Tomcat docs and much more on this subject and think that I am doing everything right, but obviously not because I keep getting the following error:

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

I do not get an error when I start Tomcat, but when I try to start 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(); } } } } 

Context for webapp:

 <?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 do not understand is the reason that the error does not mean that โ€œrootโ€ @ โ€œlocalhostโ€ is denied access when I indicated that this is a user.

What I tried:

Do I have a duplicate context.xml? Not. I removed the default value in Tomcat 6.0 / conf. I tried putting context.xml in [mywebappname] /META-INF/context.xml, but not only it didnโ€™t work, but it led to the creation of a file called TwitterSearch.xml that was auto-generated and placed in Tomcat 6.0 / conf / Catalonia / local directory. So now I'm just editing this one, and this is the only one I have.

Is this a version of Tomcat? Well, I completely reinstalled the latest version of Tomcat 6.0, so I donโ€™t think it is.

Are we missing some banks? I have tomcat-dbcp.jar, jconnector.jar and all the others that I think I should have in the Tomcat 6.0 / lib directory.

When I look at the passwords in the MySQL database, they seem to have been encoded for security purposes in a long alphanumeric string. This is normal? Should I have this in my context. Xml or just plain password?

I really don't know how I can figure this out and will be very grateful for the expert advice.

Thank you very much in advance.

Joe

+7
mysql mysql-error-1045 tomcat6 datasource
source share
2 answers

Your setup looks fine. It looks like a permission issue.

You need to provide this user access in mysql. Although Java will connect to localhost, it will do this using tcp / ip, but in mysql localhost and 127.0.0.1 have a different meaning. The release of this SQL should do the trick.

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

It is assumed that Java resolves "localhost" to 127.0.0.1, if it still does not work, you can try changing the connection string to "jdbc: mysql: //127.0.0.1: 3306 / twitter"

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

As you now know, the password is plaintext.

+9
source share

In your context.xml configuration for webapp, you must change user = "root" by username = "root"

+1
source share

All Articles