QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5127|回复: 15

十万火急在线等待,MySQL拒绝访问

[复制链接]
发表于 2005-7-16 09:49:04 | 显示全部楼层 |阅读模式
平台:Red Hat Enterprise 4.0 , J2SDK.1.4 ,Tomcat 5.0 ,MySQL 4.1.7,
mysql-connector-java-3.1.10-bin-g.jar

JSP源码如下

<%@ page import="java.sql.*"%>
<html>
<head>
<title>Test JDBC For MySQL</title>
</head>
<%@ page contentType="text/html;charset=gb2312" %>
<body>
<BR>
<%
try{
Connection con;
Class.forName("com.mysql.jdbc.Driver");
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
String dbUrl = "jdbc:mysql://localhost:3306/mysql?useUnicode=true&characterEncoding=GB2312";
String dbUser="root";
String dbPwd="w6tf2b";
con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);
}catch (Exception e) {out.println(e.getMessage());}
%>
</body>
</html>

当浏览器访时,只是显示:
Server configuration denies access to data source

请问各位大虾该如何解决```?
发表于 2005-7-16 09:59:49 | 显示全部楼层
你看看MySQL启动了没?

whereis mysql

若在这个目录下/usr/local/mysql/bin/mysql -u root

检查MySQL是否启动了
回复

使用道具 举报

 楼主| 发表于 2005-7-16 10:03:22 | 显示全部楼层
非常感谢版主的回复!

mysqladmin ping

显示的是alive,应该启动好了
回复

使用道具 举报

发表于 2005-7-16 10:07:35 | 显示全部楼层
con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);

不用交待连接哪个数据库么?

比如

String dbName = "test";

con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd,dbName);
回复

使用道具 举报

 楼主| 发表于 2005-7-16 10:12:17 | 显示全部楼层
String dbUrl = "jdbc:mysql://localhost:3306/mysql?useUnicode=true&characterEncoding=GB2312";

其中数据库的名字是 mysql

java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);
好象只有3个参数,
当我注释掉此句时,就没有错误,
//java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);
估计JDBC 加载没问题
回复

使用道具 举报

发表于 2005-7-16 10:16:26 | 显示全部楼层
如果用户名和密码都没有问题的话

那就是dbUrl出现了问题

我们知道连接的是MySQL数据库类型

但是MySQL管理着很多数据库,比如默认的test,是否需要在dbUrl中指定数据库名称

String dbUrl = "jdbc:test://localhost:3306/mysql?useUnicode=true&characterEncoding=GB2312";
回复

使用道具 举报

 楼主| 发表于 2005-7-16 13:11:35 | 显示全部楼层
在MYSQL中设置了权限
grant all privileges on TestJSP.* to 'root'@'127.0.0.1' identified by 'w6tf2b';

FLUSH privileges;

环境变量设置如下

/etc/profile
.
.
export PATH=$PATH:/home/vpopmail/bin:/usr/local/jakarta-tomcat-5.0.12/bin
export JAVA_HOME=/usr/java/j2sdk1.4.2_01
export CLASSPATH=/usr/java/j2sdk1.4.2_01/lib:/usr/java/j2sdk1.4.2_01/lib/dt.jar:/usr/java/j2sdk1.4.2_01/lib/tools.jar:/usr/local/jakarta-tomcat-5.0.12/common/lib/mysql-connector-java-3.1.10-bin.jar
export CATALINA_HOME=/usr/local/jakarta-tomcat-5.0.12

JSP原文件
<%@ page import="java.sql.*"%>
<html>
<head>
<title>Test JDBC For MySQL</title>
</head>
<%@ page contentType="text/html;charset=gb2312" %>
<body>
<BR>
<%try{
Connection con;


Class.forName("com.mysql.jdbc.Driver");
DriverManager.registerDriver(new com.mysql.jdbc.Driver());


String dbUrl = "jdbc:mysql://127.0.0.1/TestJSP";

String dbUser="root";

String dbPwd="w6tf2b";
con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);
}catch (Exception e) {out.println(e.getMessage());}

%>
</body>
</html>

显示的错误如下:
Communication link failure: java.io.IOException, underlying cause: Unexpected end of input stream ** BEGIN NESTED EXCEPTION ** java.io.IOException MESSAGE: Unexpected end of input stream STACKTRACE: java.io.IOException: Unexpected end of input stream at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:1096) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:626) at com.mysql.jdbc.Connection.createNewIO(Connection.java:1562) at com.mysql.jdbc.Connection.(Connection.java:491) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:346) at java.sql.DriverManager.getConnection(DriverManager.java:512) at java.sql.DriverManager.getConnection(DriverManager.java:171) at org.apache.jsp.DbJsp_jsp._jspService(DbJsp_jsp.java:73) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133) at javax.servlet.http.HttpServlet.service(HttpServlet.java:856) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:24 at javax.servlet.http.HttpServlet.service(HttpServlet.java:856) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:209) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:670) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:517) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:575) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666) at java.lang.Thread.run(Thread.java:534) ** END NESTED EXCEPTION **
回复

使用道具 举报

发表于 2005-7-16 14:14:20 | 显示全部楼层
Unexpected end of input stream

意外的输入流
回复

使用道具 举报

 楼主| 发表于 2005-7-16 15:35:15 | 显示全部楼层
不知道我的JDK是否有问题,如下代码,编译错误:
public class HelloWorld{
public static void main(String args[]){
System.out.println("HelloWorld");
}
}
编译错误:
[root@mail temp]# javac HelloWorld.java
HelloWorld.java:5: '}' expected
}
^
1 error
代码:
public class HelloWorld{
public static void main(String args[]){
//System.out.println("HelloWorld");
}
}
编译:
[root@mail temp]# javac HelloWorld.java
HelloWorld.java:4: '}' expected
//System.out.println("HelloWorld");
^
1 error
代码:
public class HelloWorld{
public static void main(String args[]){
String hello="HelloWorld";
}
}
编译成功无错误
回复

使用道具 举报

发表于 2005-7-16 16:48:39 | 显示全部楼层
4.1 的密码换加密方法了,PHP 4 就连不上,不知道是不是这个问题?
回复

使用道具 举报

 楼主| 发表于 2005-7-16 16:56:38 | 显示全部楼层
弄了两天,
一无所获,简直就是```闹挺```

con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);
就这句引起了一堆问题
回复

使用道具 举报

发表于 2005-7-16 17:15:11 | 显示全部楼层
PHP5连接MySQL使用ADODB都没问题的呀
回复

使用道具 举报

 楼主| 发表于 2005-7-16 18:25:17 | 显示全部楼层
终于搞定了``
非常感谢``涩兔子的帮助  3ku```

当浏览器访时,只是显示:
Server configuration denies access to data source
这个错误是访问权限没有设置,如下设置:
grant all privileges on 数据库名.* to '账号'@'主机地址' identified by '密码';
FLUSH privileges;
出现如下错误:
Communication link failure: java.io.IOException, underlying cause: Unexpected end of input stream .......

下载了个最新的JDBC驱动mysql-connector-java-3.2.0-alpha-bin.jar
就可以解决了,如果解决不了,可能是重新使用了一个已经关闭了的联结.
http://www-128.ibm.com/developerworks/forums/dw_thread.jsp?message=13707804&cat=10&thread=60963&forum=244

There are two case for thus exception I known:
the first type you use the old version of the mysql driver;
the second, your application reuse the connection which has been closed some where.
回复

使用道具 举报

 楼主| 发表于 2005-7-16 20:18:16 | 显示全部楼层
使用了较为低版本的MySQL

应用程序重复连接
回复

使用道具 举报

 楼主| 发表于 2005-8-10 14:44:01 | 显示全部楼层
又一Mysql 权限错误,可用grant 更改用户权限解决,grant all privileges on Db.* to 'Username'@'localhost' identified by '12345';

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

exception

javax.servlet.ServletException: null, message from server: "#HY000Host 'localhost.localdomain' is not allowed to connect to this MySQL server"
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:673)
org.apache.jsp.admin.fuser_jsp._jspService(fuser_jsp.java:173)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:24
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

root cause

java.sql.SQLException: null, message from server: "#HY000Host 'localhost.localdomain' is not allowed to connect to this MySQL server"
com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1023)
com.mysql.jdbc.Connection.createNewIO(Connection.java:1699)
com.mysql.jdbc.Connection.(Connection.java:40
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:270)
java.sql.DriverManager.getConnection(DriverManager.java:512)
java.sql.DriverManager.getConnection(DriverManager.java:171)
mypack.WceeDB.getConnection(WceeDB.java:21)
mypack.WceeDB.getForeignUser(WceeDB.java:17
org.apache.jsp.admin.fuser_jsp._jspService(fuser_jsp.java:110)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:24
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

note The full stack trace of the root cause is available in the Tomcat logs.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-16 20:33 , Processed in 0.043429 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

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