URGENT!!! - Serious Problem: Cannot create PoolableConnectionFactory
843859Apr 22 2006 — edited Apr 27 2006Hi all,
I�ll appreciate a lot your URGENT HELP with this problem.
I�ve developed a web App wich works fine in my dev. environment but, when try it in the customer production env. I�ve a SERIOUS CONNECTIVITY PROBLEM. The app. consist basically of a Java (J2ME)client wich uses a Servlet to get data from a MySQL Server in Tomcat, using JDBC - DBCP.
When I try it from "www.nasinibursatil.com.ar/rnasini/servlet/ServletTest"
I get ERROR:
org.apache.tomcat.dbcp.dbcp.SQLNestedException:
Cannot create PoolableConnectionFactory (Server connection failure during transaction). Due to underlying exception:
'java.sql.SQLException
MESSAGE: null,
message from server: "Host 'www.nasinibursatil.com.ar' is not allowed to connect to this MySQL server"
** BEGIN NESTED EXCEPTION **
STACKTRACE:
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:991)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2683)
at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)
at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:877)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:554)
at ServletTest.doGet(ServletTest.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:754)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:684)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:876)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)
** END NESTED EXCEPTION **
Attempted reconnect 3 times. Giving up.)
1) Dev. environment:
J2SDK: 1.5.0_04_b05
MySQL Server: 3.23.49-nt
Tomcat: 5.0 (without Apache)
JDBC Driver: "com.mysql.jdbc.Driver"
MySQL definitions:
DataBase: "nasini"
Table: "especies"
User: GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY 'rootpass' WITH GRANT OPTION
2) Deployment Environment: (preexistent due to a PHP app.)
J2SDK: 1.5.0_06
MySQL: 4.1.10a
JDBC Driver: Connector/J
Tomcat: 5.5.15 (with Apache)
MySQL Definitions:
Data Base: "nasini"
Table: "nasini"
User: "root"
Password: ""
3)Directory Structure: (where "rnasini" is the app. docBase)
$CATALINA-HOME
webapps
rnasini
WEB-INF -------------> (contains web.xml)
classes ------------->(contains my Servlet)
4) "server.xml" file (in $CATALINA_HOME/conf):
<!-- Server Configuration File -->
<Server port="8005" shutdown="SHUTDOWN">
<!-- Global JNDI resources -->
<GlobalNamingResources>
<!-- Test entry for demonstration purposes -->
<Environment name="simpleValue" type="java.lang.Integer" value="30"/>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource
name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml"
/>
</GlobalNamingResources>
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" (and therefore the web applications visible
within that Container). Normally, that Container is an "Engine",
but this is not required.
Note: A "Service" is not itself a "Container", so you may not
define subcomponents such as "Valves" or "Loggers" at this level.
-->
<!-- Define the Tomcat Stand-Alone Service -->
<Service name="Catalina">
<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
<!-- Note : To disable connection timeouts, set connectionTimeout value
to 0 -->
<!-- Define the top level container in our container hierarchy -->
<Engine name="Catalina" defaultHost="localhost">
<!-- I let this Realm definition here but I�m not using Realms at all!!! -->
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits that are
performed against this UserDatabase are immediately available
for use by the Realm.
-->
<Realm
className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"
/>
<!-- Define the Default Virtual Host. -->
<Host
name="localhost"
appBase="webapps"
unpackWARs="true"
autoDeploy="true"
xmlValidation="false"
xmlNamespaceAware="false">
<!-- ******************************************************************** -->
<!-- Here I start adding the lines suggested in the Apache docummentation -->
<!-- ******************************************************************** -->
<Context path="/rnasini" docBase="rnasini"
debug="5" reloadable="true"
crossContext="true">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_rnasini_log." suffix=".txt"
timestamp="true"/>
<Resource
type="javax.sql.DataSource"
auth="Container"
name="jdbc/TestDB"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
maxActive="100"
maxIdle="30"
maxWait="10000"
username="root"
password=""
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/nasini?autoReconnect=true"
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"
/>
</Context>
<!-- ***************************************************************** -->
<!-- My addings ends here --> <!-- ***************************************************************** -->
</Host>
</Engine>
</Service>
</Server>
4) "web.xml" file (in WEB-INF):
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<!-- EJ.Blufstein(01-04-06): para testing de acceso a "ServletHola" en TOMCAT-5.5. -->
<servlet>
<servlet-name>ServletHola</servlet-name>
<servlet-class>ServletHola</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletHola</servlet-name>
<url-pattern>/servlet/ServletHola/*</url-pattern>
</servlet-mapping>
<!-- NOTA: el <url-pattern> podria ser (M.Hall): "/ServletHola" -->
<!-- EJ.Blufstein(01-04-06): Fin agregado para testing -->
<!-- BlufsteinEJ(03-04-06): para testing de ServletAccess -->
<servlet>
<servlet-name>ServletAccess</servlet-name>
<servlet-class>ServletAccess</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletAccess</servlet-name>
<url-pattern>/servlet/ServletAccess/*</url-pattern>
</servlet-mapping>
<!-- NOTA: el <url-pattern> podria ser (M.Hall): "/ServletHola" -->
<!-- BlufsteinEJ(03-04-06): Fin agregado para testing -->
<!-- BlufsteinEJ(04-04-06): para testing de ServletOK -->
<servlet>
<servlet-name>ServletOK</servlet-name>
<servlet-class>ServletOK</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletOK</servlet-name>
<url-pattern>/servlet/ServletOK/*</url-pattern>
</servlet-mapping>
<!-- BlufsteinEJ(04-04-06): Fin agregado para testing -->
<!-- BlufsteinEJ(04-04-06): para testing de ServletTest -->
<servlet>
<servlet-name>ServletTest</servlet-name>
<servlet-class>ServletTest</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletTest</servlet-name>
<url-pattern>/servlet/ServletTest/*</url-pattern>
</servlet-mapping>
<!-- BlufsteinEJ(04-04-06): Fin agregado para testing -->
<description>MySQL Test App</description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
5) My ServletTest:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import javax.sql.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
/* -------- Simpe Servlet for test JDBC - Tomcat 5.5.15 / MySQL connection ----------- */
public class ServletTest extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
DataSource dataSource = null;
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
try{
out.println("************ NORMAL SERVLET BEHAVIOR ************");
Class Driver = Class.forName("com.mysql.jdbc.Driver");
out.println("Driver-JDBC: " + Driver);
Class Factory = Class.forName("org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory");
out.println("dbcp-Factory: " + Factory);
Context initContext = new InitialContext();
out.println("initContext: " + initContext);
Context envContext = (Context)initContext.lookup("java:/comp/env");
out.println("envContext: " + envContext);
dataSource = (DataSource)envContext.lookup("jdbc/TestDB");
out.println("dataSource: " + dataSource);
} catch(Exception e1) {
out.println("Error-1: " + e1);
}
try{
out.println("");
out.println("******* BAD BEHAVIOR - CANNOT GET CONNECTION *******");
Connection conn = dataSource.getConnection("root", "");
out.println("I�m connected");
} catch(Exception e2) {
out.println("Error-2: " + e2);
}
// I�ll stop here because I cannot do "Statement st = conn.createStatement()" in
// order to obtain a ResultSet with data so, I comment the following lines.
// try{
// Statement st = conn.createStatement();
// ResultSet rs = s.executeQuery("SELECT * FROM especies");
// while(rs.next()){
// //do something with the data
// }
// } catch (Exception ex) {
// out.println("Error: " + ex);
// }
}
}
Please, I need URGENT HELP with this problem.!!!!
Thanks in advance.
BlufsteinEJ
<ernestojb@yahoo.co.ar>