十万火急在线等待,MySQL拒绝访问
平台: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
请问各位大虾该如何解决```? 你看看MySQL启动了没?
whereis mysql
若在这个目录下/usr/local/mysql/bin/mysql -u root
检查MySQL是否启动了 非常感谢版主的回复!
mysqladmin ping
显示的是alive,应该启动好了 con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);
不用交待连接哪个数据库么?
比如
String dbName = "test";
con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd,dbName); 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 加载没问题 如果用户名和密码都没有问题的话
那就是dbUrl出现了问题
我们知道连接的是MySQL数据库类型
但是MySQL管理着很多数据库,比如默认的test,是否需要在dbUrl中指定数据库名称
String dbUrl = "jdbc:test://localhost:3306/mysql?useUnicode=true&characterEncoding=GB2312"; 在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:248) 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 ** Unexpected end of input stream
意外的输入流 :x 不知道我的JDK是否有问题,如下代码,编译错误:
public class HelloWorld{
public static void main(String args[]){
System.out.println("HelloWorld");
}
}
编译错误:
# javac HelloWorld.java
HelloWorld.java:5: '}' expected
}
^
1 error
代码:
public class HelloWorld{
public static void main(String args[]){
//System.out.println("HelloWorld");
}
}
编译:
# 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";
}
}
编译成功无错误 4.1 的密码换加密方法了,PHP 4 就连不上,不知道是不是这个问题? 弄了两天,
一无所获,简直就是```闹挺``` :evil:
con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);
就这句引起了一堆问题 PHP5连接MySQL使用ADODB都没问题的呀 :idea: 终于搞定了`` :wink:
非常感谢``涩兔子的帮助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. 使用了较为低版本的MySQL
应用程序重复连接 又一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:248)
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:408)
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:178)
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:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
note The full stack trace of the root cause is available in the Tomcat logs.
页:
[1]
2