Connecting Tomcat 6 and MySQL 5 (+ Plandora project management software)
I realise there have been a lot of discussions on this topic, but I need a bit of help with my specific issue.
First of all, the details:
OS: Ubuntu Server 11.04 Database: MySQL 5.1.54 Web Server: Apache Tomcat 6
Software I am attempting to install is Plandora 1.10.4 ( http://www.plandora.org/ ).
I am attempting to follow the installation process here: http://www.plandora.org/project.htm, plus looking at tutorials elsewhere and the Tomcat 6 documentation.
The .war file was successfully installed via the manager and I'm currently looking at the login screen. When I attempt to connect using the default root account for first-time connections, I am shown the following error:
org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.GeneratedConstructorAccessor28.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:344)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2333)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2370)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2154)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.GeneratedConstructorAccessor25.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
at org.apache.commons.dbcp.BasicD开发者_Go百科ataSource.validateConnectionFactory(BasicDataSource.java:1556)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at com.pandora.dao.DataAccess.getConnection(DataAccess.java:66)
at com.pandora.dao.DataAccess.getConnection(DataAccess.java:45)
at com.pandora.dao.UserDAO.getObjectByUsername(UserDAO.java:375)
at com.pandora.bus.UserBUS.authenticateUser(UserBUS.java:211)
at com.pandora.delegate.UserDelegate.authenticateUser(UserDelegate.java:102)
at com.pandora.gui.struts.action.LoginAction.doLogin(LoginAction.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at com.pandora.gui.struts.action.GeneralStruts.process(GeneralStruts.java:54)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:679)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:327)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:193)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
at java.net.Socket.connect(Socket.java:546)
at java.net.Socket.connect(Socket.java:495)
at java.net.Socket.<init>(Socket.java:392)
at java.net.Socket.<init>(Socket.java:235)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:257)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:294)
... 48 more
I assume from this that I have correctly installed the MySQL driver (mysql-connector-java-5.1.16-bin.jar) in CATALINA_HOME/lib (i.e. /usr/share/tomcat6/lib) and that the issue is with the connection details.
I have created a user in MySQL, a database for Plandora (and loaded content from provided .sql script into it), and granted full access on that specific database to the Plandora user.
I have incorporated the contents of the context.xml file provided with Plandora with the context.xml file I found already present in CATALINA_BASE/conf (i.e. /var/lib/tomcat6/conf). It now reads as follows:
<?xml version='2.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- The contents of this file will be loaded for each web application -->
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="jdbc/plandora" auth="Container"
type="javax.sql.DataSource" username="example_username" password="example_password"
driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/plandora"
maxActive="50" maxIdle="20"/>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<!-- Uncomment this to enable Comet connection tacking (provides events
on session expiration as well as webapp lifecycle) -->
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
-->
</Context>
I haven't changed any other files provided with plandora. As for Tomcat 6, I have added a user to access the manager and host-manager webapps but that's about it. I have left server.xml alone as suggested for version 6 of Tomcat.
I think that covers what I've done so far. Any suggestions would be appreciated :)
Caused by: java.net.ConnectException: Connection refused
At that point, the JDBC driver is successfully loaded and the JDBC URL of jdbc:mysql://localhost:3306/plandora
is correct (at least, for the JDBC driver). So those are not an issue. What is happening here is that the connection acquirement has been, well, refused. This basically means that there's nothing on port 3306
of host localhost
which is accepting TCP/IP connections.
This can have several causes:
- MySQL is not started.
- MySQL does physically not run on
localhost
machine. - MySQL does not listen on the IP behind
localhost
(mysqld
bind-address
is not set to127.0.0.1
) - MySQL does not accept TCP/IP connections (
mysqld
has the--skip-networking
option). - MySQL port number as definied in MySQL's
my.cnf
is not3306
. - MySQL has run out of connections.
- Some firewall/proxy is blocking the connection.
I guess that it's the --skip-networking
option. I've seen this more than often being the cause in Ubuntu + MySQL + JDBC connectivity troubles. It's somehow by default turned on on Ubuntu.
精彩评论