连接Tomcat 6和MySQL 5 (+ Plandora项目管理软件)



我知道关于这个话题已经有很多讨论,但是我需要一些帮助来解决我的具体问题。

首先,详细说明:

OS: Ubuntu Server 11.04数据库: MySQL 5.1.54Web Server: Apache Tomcat 6

我试图安装的软件是Plandora 1.10.4 (http://www.plandora.org/)。

我尝试在这里遵循安装过程:http://www.plandora.org/project.htm,再加上查看其他地方的教程和Tomcat 6文档。

.war文件已通过管理器成功安装,我目前正在查看登录屏幕。当我尝试使用默认的根帐户进行第一次连接时,出现以下错误:

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

我假设我已经在CATALINA_HOME/lib(即/usr/share/tomcat6/lib)中正确安装了MySQL驱动程序(MySQL -connector-java-5.1.16-bin.jar),问题是连接细节。

我已经在MySQL中创建了一个用户,一个用于planandora的数据库(并从提供的。sql脚本加载内容到它),并授予对该特定数据库的完全访问权限给planandora用户。

我已经将Plandora提供的context.xml文件的内容与我发现已经存在于CATALINA_BASE/conf(即/var/lib/tomcat6/conf)中的context.xml文件合并。现在它的内容如下:

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

我没有更改plandora提供的任何其他文件。至于Tomcat 6,我添加了一个用户来访问管理器和主机-管理器web应用程序,但仅此而已。按照Tomcat版本6的建议,我保留了server.xml。

我想这就涵盖了我目前为止所做的。如有任何建议,不胜感激:)

Caused by: java.net.ConnectException: Connection refused

此时,JDBC驱动程序已成功加载,并且jdbc:mysql://localhost:3306/plandora的JDBC URL是正确的(至少对于JDBC驱动程序是正确的)。所以这些都不是问题。这里发生的是,连接获得被拒绝了。这基本上意味着主机localhost3306端口上没有任何东西正在接受TCP/IP连接。

这可能有几个原因:

    MySQL未启动。 MySQL不能在localhost机器上运行。
  • MySQL不监听localhost后面的IP (mysqld bind-address没有设置为127.0.0.1)
  • MySQL不接受TCP/IP连接(mysqld--skip-networking选项)。
  • MySQL的my.cnf中定义的MySQL端口号不是3306
  • MySQL已经没有连接了。
  • 某个防火墙/代理正在阻止连接。

这是--skip-networking选项。我经常在Ubuntu + MySQL + JDBC连接问题中看到这种情况。

最新更新