LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1613|回复: 11

Tomcat和resin都无法连接数据库mysql,请大侠帮忙!急

[复制链接]
发表于 2003-6-17 17:34:05 | 显示全部楼层 |阅读模式
我的tomcat用的是mysql-connector-java-2.0.14-bin.jar驱动,库放在/usr/local/jakarta-tomcat-4.1.12/common/lib下,用root用户ssh能连mysql,在tomcat的server.xml中配了连接池,发现不能连接mysql,是什么原因啊?
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: java.sql.SQLException: Invalid authorization specification: Access denied for user: 'root@ld-vod' (Using password: YES)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:248)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2396)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:405)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:380)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:508)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:533)
at java.lang.Thread.run(Thread.java:536)


root cause

org.apache.commons.dbcp.DbcpException: java.sql.SQLException: Invalid authorization specification: Access denied for user: 'root@ld-vod' (Using password: YES)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:85)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:184)
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(Unknown Source)
at org.apache.commons.dbcp.AbandonedObjectPool.borrowObject(AbandonedObjectPool.java:117)
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:110)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:312)
at org.apache.jsp.film_jsp._jspService(film_jsp.java:56)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:204)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2396)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:405)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:380)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:508)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:533)
at java.lang.Thread.run(Thread.java:536)
Caused by: java.sql.SQLException: Invalid authorization specification: Access denied for user: 'root@ld-vod' (Using password: YES)
at com.mysql.jdbc.MysqlIO.init(Unknown Source)
at com.mysql.jdbc.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.jdbc2.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.Driver.connect(Unknown Source)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:83)
... 41 more



--------------------------------------------------------------------------------

Apache Tomcat/4.1.12

在resin下也是配的连接池,同样不能连接出现如下:
500 Servlet Exception
java.sql.SQLException: Dropped connection
        at com.caucho.jdbc.mysql.DatabaseConnection.readStatus(DatabaseConnection.java:574)
        at com.caucho.jdbc.mysql.DatabaseConnection.login(DatabaseConnection.java:191)
        at com.caucho.jdbc.mysql.DatabaseConnection.<init>(DatabaseConnection.java:147)
        at com.caucho.jdbc.mysql.Connection.create(Connection.java:126)
        at com.caucho.jdbc.mysql.Driver.connect(Driver.java:113)
        at com.caucho.sql.XADataSourceAdapter.getXAConnection(XADataSourceAdapter.java:119)
        at com.caucho.sql.XADataSourceAdapter.getPooledConnection(XADataSourceAdapter.java:141)
        at com.caucho.sql.DBPool.createConnection(DBPool.java:1441)
        at com.caucho.sql.DBPool.getPooledConnection(DBPool.java:1334)
        at com.caucho.sql.DBPool.getConnection(DBPool.java:1198)
        at com.caucho.sql.DBPool.getConnection(DBPool.java:1175)
        at _vod._film__jsp._jspService(/vod/film.jsp:14)
        at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
        at com.caucho.jsp.Page.subservice(Page.java:497)
        at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
        at com.caucho.server.http.Invocation.service(Invocation.java:315)
        at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
        at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246)
        at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:164)
        at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
        at java.lang.Thread.run(Thread.java:536)


--------------------------------------------------------------------------------
Resin 2.1.8 (built Thu Mar 6 11:50:23 PST 2003)

请高人指点迷津!万分感谢!!
发表于 2003-6-17 17:55:01 | 显示全部楼层
是数据库连接认证的问题。从你的出错信息来看是这样的。
你用这个看能不能连上数据库:
psql -h 主机IP -u 你用在JSP中的数据库用户名  -p  数据库名
输入密码,看能不能连入?
发表于 2003-6-17 18:17:00 | 显示全部楼层
 楼主| 发表于 2003-6-18 07:26:33 | 显示全部楼层
非常谢谢两位版主,我用psql -h 主机IP -u 你用在JSP中的数据库用户名 -p 数据库名出现如下:
User name: root
Password:
psql: could not connect to server: Connection refused
        Is the server running on host 61.237.24.4 and accepting
        TCP/IP connections on port vod?
不能连到数据库,但我用netstat -na | grep 3306 能看到端口在监听。
   我用./mysql -u root -p
连到mysql后查到我的user表如下:
mysql> select user,password,host from user;
+------+------------------+-----------+
| user | password         | host      |
+------+------------------+-----------+
| root | 3d9c9bc5012cc6f7 | localhost |
| root |                  | vod2      |
|      |                  | localhost |
|      |                  | vod2      |
| root | 3d9c9bc5012cc6f7 | %         |
| ldzw | 2c7e725b105c9f19 | localhost |
+------+------------------+-----------+
6 rows in set (0.00 sec)
不知还是不是我的user表用户权限问题,还请黄版主看看!
resin和tomcat都是显示如下错误:
java.sql.SQLException: Cannot connect to MySQL server on 61.237.24.4:3306.
Is there a MySQL server running on the machine/port you are trying to connect
to? (java.lang.NumberFormatException)
        at com.mysql.jdbc.Connection.connectionInit(Unknown Source)
        at com.mysql.jdbc.jdbc2.Connection.connectionInit(Unknown Source)
        at com.mysql.jdbc.Driver.connect(Unknown Source)
        at com.caucho.sql.XADataSourceAdapter.getXAConnection(XADataSourceAdapter.java:119)
        at com.caucho.sql.XADataSourceAdapter.getPooledConnection(XADataSourceAdapter.java:141)
        at com.caucho.sql.DBPool.createConnection(DBPool.java:1441)
        at com.caucho.sql.DBPool.getPooledConnection(DBPool.java:1334)
        at com.caucho.sql.DBPool.getConnection(DBPool.java:1198)
        at com.caucho.sql.DBPool.getConnection(DBPool.java:1175)
        at _vod._film__jsp._jspService(/vod/film.jsp:14)
        at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
        at com.caucho.jsp.Page.subservice(Page.java:497)
        at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
        at com.caucho.server.http.Invocation.service(Invocation.java:315)
        at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
        at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246)
        at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
        at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
        at java.lang.Thread.run(Thread.java:536)
发表于 2003-6-18 08:25:28 | 显示全部楼层
用户权限没有问题呀。
真搞不懂,它的提示好像是说没有在固定的端口上运行mysql
对了,你用的地什么系统?
是rh8吗?如果是这个系统可就有点问题了。
在rh8上的mysql有一个bug,不能远程连接。这个原来我也遇到过,我原来是用myodbc远端连接mysql.
建议你升级一下你的glibc,好像是这个东东引起的。
或者你在装有mysql服务器的那台机器上的/etc/hosts文件里加上你要来访问mysql客户机的ip地址入机器名。应该可以了。
试试看。
 楼主| 发表于 2003-6-18 11:08:27 | 显示全部楼层
黄版主有请了,我用的是rh7.3,内核版本是2.4.18,这应该没有问题吧,以前有人用过的。不知和这个有没有关系:
   一个MySQL客户可以两种不同的方式连接mysqld服务器:Unix套接字,它通过在文件系统中的一个文件(缺省“/tmp/mysqld.sock”)进行连接;或TCP/IP,它通过一个端口号连接。Unix套接字比TCP/IP更快,但是只有用在连接同一台计算机上的服务器。如果你不指定主机名或如果你指定特殊的主机名localhost,使用Unix套接字。不知是我的mysql只能用unix套接字来连,而TCP/IP无法连接,不知是这是问题出在这?
发表于 2003-6-18 17:59:36 | 显示全部楼层
这个不是问题呀,
mysql没有用UNIX套接字联接的吧。它应该只是用TCP/IP协议联接才对。
要不你换个Mysql的JDBC驱动程序看看。
 楼主| 发表于 2003-6-18 19:51:54 | 显示全部楼层
但是我用netstat -na 能看到这个unix  2      [ ACC ]     STREAM     LISTENING     27913  /tmp/mysql.sock
驱动是换了无数个了,3.0.6的还有1.2的都用了,都不行,真是步步艰难啊~
发表于 2003-6-19 08:06:27 | 显示全部楼层
  ,再仔细检查一下。说不定就是一个很小的问题,小到你不能相信的问题呢。
我也经常会出现这样的情况。不要气馁。我原来学习java的时候就为了说一个hello world就花了我好大的功夫呀。
 楼主| 发表于 2003-6-19 08:50:10 | 显示全部楼层
不知道和mysql的版本有没有关系,把版本降低再看看,程序员的乐趣可能就在一次一次的站胜这些关卡!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表