You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mel McGuire <me...@mel.mcguire.name> on 2009/03/23 06:24:48 UTC
Cannot create PoolableConnectionFactory
Hi,
I've been away from my app for 3 months with only 4-5 tests in the interim (lots of tests while I was working on it though). Now, I have a
"Connot create PoolableConnectionFactory" problem.
What I've done is at the end of the email.
Some new places to look at would be helpful.
Setup:
--------------------------------------------------------------------
Vista (with auto update--I should be ok)
Tomcat 6.0.18 (running in a window--not running as a service)
Mysql 5.0 (running as a service)
mysql-connector-java-5.1.7-bin.jar
java 1.6.0_07 and also jre6 (new)
No IDE yet.
No problem seen with mysql or the mysql command line utility.
Tomcat comes up and down alright.
--------------------------------------------------------------------
context.xml
--------------------------------------------------------------------
<Resource name="jdbc/blogdb"
auth="Container"
type="javax.sql.DataSource"
maxActive="20"
maxIdle="5"
maxWait="10000"
username="root"
password="xxxxx"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/nlocalhost"
removeAbandoned="true"
removeAbandonedTimeout="120" />
--------------------------------------------------------------------
HTTP Status 500 error report:
--------------------------------------------------------------------
java.lang.NullPointerException
PublicTopFrameset.doGet(PublicTopFrameset.java:109)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
--------------------------------------------------------------------
Tomcat error report:
--------------------------------------------------------------------
AbandonedObjectPool is used (org.apache.tomcat.dbcp.dbcp.AbandonedObjectPool&b8f8eb)
LogAbandoned: false
RemoveAbandoned: true
RemoveAbandonedTimeout: 120
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure
Last packet sent to the server was 0 ms ago.)
-------------------------------------------------------------------
The failing servlet:
-------------------------------------------------------------------
...
private ServletContext servletContext = null;
private DataSource dataSource = null;
public void init(ServletConfig config)
throws ServletException
{
super.init(config);
servletContext = config.getServletContext();
dataSource = (DataSource)servletContext.getAttribute("dataSource");
//The dataSource is set by an initialization servlet running at no 1
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
Connection con = null;
...
try
{ //The error occurs here.
con = dataSource.getConnection();
}
catch (SQLException e){System.out.println(e.toString());}
...
}
-------------------------------------------------------------------
So far:
-------------------------------------------------------------------
.In the con = dataSource.getConnection(); line, dataSource is not null.
.I tested with my Norton firewall off. The problem persisted.
.When the mysql port is changed to 3308, the error message is the same.
I conclude that the error occurs before there is an attempt to use
the mysql port?
.I bit on a Sun Java upgrade popup several weeks ago but I believe I tested
ok after it was installed. Anyway, the upgrade left a CLASSPATH variable
containing only jre6. I temporarily removed the CLASSPATH variable but
the problem persisted. I copied some .jar files into the new
jre6/lib/ext folder from the jre1.6.0_07/lib/ext folder. No luck.
.A few days ago, my computer hung at "shutting down" (first time ever) and I
pulled the electrical plug and restarted. I don't belive I tested
my app after the restart but I didn't notice anything else wrong.
.I've not been able to resolve it through Internet search.
Thanks,
Mel McGuire
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Cannot create PoolableConnectionFactory
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Mel,
On 3/23/2009 1:24 AM, Mel McGuire wrote:
> No problem seen with mysql or the mysql command line utility.
> Tomcat comes up and down alright.
[snip]
> url="jdbc:mysql://localhost:3306/nlocalhost"
> removeAbandoned="true"
> removeAbandonedTimeout="120" />
I would add:
logAbandoned="true"
validationQuery="/* PING */ SELECT 1"
Note that using 'root' is probably not the best strategy, here. ;)
> HTTP Status 500 error report:
> --------------------------------------------------------------------
> java.lang.NullPointerException
> PublicTopFrameset.doGet(PublicTopFrameset.java:109)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> --------------------------------------------------------------------
Obviously, your webapp should be checking for null references. I know
your problem is deeper than this, but this error is obviously your
code's fault.
> Tomcat error report:
> --------------------------------------------------------------------
> AbandonedObjectPool is used (org.apache.tomcat.dbcp.dbcp.AbandonedObjectPool&b8f8eb)
> LogAbandoned: false
> RemoveAbandoned: true
> RemoveAbandonedTimeout: 120
> org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure
> Last packet sent to the server was 0 ms ago.)
This indicates that Java can't contact the server. You mentioned that
the mysql command-line utility connects just fine. Can you do this and
see what happens:
C> mysql -h 127.0.0.1 -u root -p nlocalhost
and see if that connects? I don't think win32 uses anything other than
TCP/IP for communication (*NIX systems can use a named pipe on the
filesystem and ignore networking altogether) but using 127.0.0.1 as the
host (/not/ "localhost") disables that behavior in the client.
> private DataSource dataSource = null;
>
> public void init(ServletConfig config)
> throws ServletException
> {
> super.init(config);
> servletContext = config.getServletContext();
> dataSource = (DataSource)servletContext.getAttribute("dataSource");
You really shouldn't do this. You should use JNDI to get the DataSource
each time you need it, rather than caching a copy of that object
somewhere (like the application scope, as you've done here).
A JNDI fetch is cheap and more robust (you can replace the DataSource at
runtime and everyone starts using it right away, instead of having to
bounce the app). Also, DataSource is not guaranteed to be threadsafe so
you never know if it will even work properly in a shared situation
(which you have here).
> { //The error occurs here.
> con = dataSource.getConnection();
Right: you need to check for null ;)
> .When the mysql port is changed to 3308, the error message is the same.
> I conclude that the error occurs before there is an attempt to use
> the mysql port?
Yes. Your machine can't contact MySQL. Stupid question: Is MySQL
running? (Probably, since you said the command-line works).
Also, are you running Tomcat under a security manager (i.e. with the
"-security" switch)? If so, you could have a permissions problem.
> .I bit on a Sun Java upgrade popup several weeks ago but I believe I tested
> ok after it was installed. Anyway, the upgrade left a CLASSPATH variable
> containing only jre6. I temporarily removed the CLASSPATH variable but
> the problem persisted. I copied some .jar files into the new
> jre6/lib/ext folder from the jre1.6.0_07/lib/ext folder. No luck.
You should ignore the CLASSPATH environment variable. When you installed
Tomcat, did you use the installer, or did you just unzip it? I'm asking
because I think the Tomcat service points to a specific JRE version. If
Tomcat is doing /anything/ (which it is), your upgrade doesn't appear to
have broken anything.
> .A few days ago, my computer hung at "shutting down" (first time ever) and I
> pulled the electrical plug and restarted. I don't belive I tested
> my app after the restart but I didn't notice anything else wrong.
I thought this was just called "running Microsoft windows". ;)
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAknKLfQACgkQ9CaO5/Lv0PB4pgCeJtbNU3pU4OXbg02IuW7qneOZ
LE0An0Wc7CvmwC+Bm6tg3GjHLQvxBtsK
=JkQk
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org