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> <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