Topic: 高手sos!!! 连接不上mysql的问题 |
Print this page |
1.高手sos!!! 连接不上mysql的问题 | Copy to clipboard |
Posted by: wilson751 Posted on: 2004-12-20 18:46 高手sos!!! 用一个.jsp程序,查询mysql的数据库中的一个表,结果:数据库连接失败。 但是我在dos下,用这个用户连接mysql,却可以查到数据。 具体问题: 运行到 Connection con=DriverManager.getConnection(url,user,password); 就出现异常,页面显示:“数据库连接失败”。 --------------------------------------------------------- 打印异常如下: java.sql.SQLException: 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.lang.Thread.run(Thread.java:534) ** END NESTED EXCEPTION ** ----------------------------------------------------------------------------------------- 下面是我的详细操作步骤,请高手指点!!! 环境: win2000; tomcat4.1; F:\mysql-4.1.8-win; 1. 创建了一个用户; 用户名:test 密码:test ----命令: grant select,insert,update,delete on testaddressbook.* to test@localhost identified by "test"; --创建成功. 2. 创建testaddressbook数据库和表addressbooktable; mysql -uroot -proot < F:\tomcat4.1\webapps\addressbook\sql\test.sql --创建成功 ####################### test.sql DROP DATABASE IF EXISTS testaddressbook; create database testaddressbook; use testaddressbook; create table addressbooktable ( id int auto_increment primary key, name varchar(30), address varchar(255), phone varchar(20) ); insert into addressbooktable (name,address,phone) values ('jjx','zhejiang yuyao','0574-2222222'); 3. 将mysql-connector-java-2.0.14-bin.jar, 放到F:\tomcat4.1\common\lib之下。 4.启动tomcat,运行测试程序:testmysqljdbc.jsp, 提示:数据库连接不上。 ####################### testmysqljdbc.jsp <html><head><title>测试</title></head> <body><center> <%@ page language="java" import="java.sql.*" contentType="text/html;charset=gb2312" %> <% String driver="org.gjt.mm.mysql.Driver"; String url="jdbc:mysql://localhost:3306/testaddressbook"; String user="test"; String password="test"; try{ Class.forName(driver); }catch(Exception e){ out.println("无法加载驱动程序!!"+driver); e.printStackTrace(); } try { Connection con=DriverManager.getConnection(url,user,password); /* if(!con.isClosed( )) out.println("数据库连接成功!"); */ Statement sqlStmt=con.createStatement (java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY); String sqlQuery="select * from addressbooktable"; ResultSet sqlRst=sqlStmt.executeQuery (sqlQuery); out.println("<BR>"); while (sqlRst.next()) { out.println(sqlRst.getString(1)); out.println(sqlRst.getString(2)); out.println(sqlRst.getString(3)); } con.close( ); } catch(SQLException ee) {out.println("数据库连接失败!"); } %> </center> </body> </html> |
2.Re:高手sos!!! 连接不上mysql的问题 [Re: wilson751] | Copy to clipboard |
Posted by: wilson751 Posted on: 2004-12-21 08:49 这里人也不多啊 |
3.Re:高手sos!!! 连接不上mysql的问题 [Re: wilson751] | Copy to clipboard |
Posted by: jameszhang Posted on: 2004-12-21 08:57 报的错误贴上,把Exception 信息打印出来 |
4.Re:高手sos!!! 连接不上mysql的问题 [Re: wilson751] | Copy to clipboard |
Posted by: 九佰 Posted on: 2004-12-21 09:57 catch后面跟上printStackTrace方法 catch (SQLException ee) { ee.printStackTrace(); } 看看错在那里 |
5.Re:高手sos!!! 连接不上mysql的问题 [Re: wilson751] | Copy to clipboard |
Posted by: wilson751 Posted on: 2004-12-21 10:09 运行到 Connection con=DriverManager.getConnection(url,user,password); 就出现异常, 页面显示:“数据库连接失败” |
6.Re:高手sos!!! 连接不上mysql的问题 [Re: wilson751] | Copy to clipboard |
Posted by: 九佰 Posted on: 2004-12-21 13:08 把这句ee.printStackTrace();加到out.println("数据库连接失败!");后面 看后台输出的错误信息 |
7.多谢九佰,异常见里面 [Re: wilson751] | Copy to clipboard |
Posted by: wilson751 Posted on: 2004-12-21 13:13 用ee.printStackTrace();捕获的异常: 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.<init>(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.testmysqljdbc_jsp._jspService(testmysqljdbc_jsp.java:6 5) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper .java:210) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:2 95) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl icationFilterChain.java:247) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF ilterChain.java:193) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV alve.java:256) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex t.invokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav a:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV alve.java:191) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex t.invokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav a:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java: 2422) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j ava:180) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex t.invokeNext(StandardPipeline.java:643) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatche rValve.java:171) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex t.invokeNext(StandardPipeline.java:641) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j ava:163) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex t.invokeNext(StandardPipeline.java:641) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav a:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal ve.java:174) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex t.invokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav a:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:19 9) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java :828) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce ssConnection(Http11Protocol.java:700) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java :584) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP ool.java:683) at java.lang.Thread.run(Thread.java:534) ** END NESTED EXCEPTION ** |
8.Re:高手sos!!! 连接不上mysql的问题 [Re: wilson751] | Copy to clipboard |
Posted by: 九佰 Posted on: 2004-12-21 13:32 感觉你的mysql没连接上,不能访问。 用图形化的客户端mysql-front连接试试 |
9.Re:高手sos!!! 连接不上mysql的问题 [Re: wilson751] | Copy to clipboard |
Posted by: wilson751 Posted on: 2004-12-21 13:47 请问哪里有下? |
10.Re:高手sos!!! 连接不上mysql的问题 [Re: wilson751] | Copy to clipboard |
Posted by: mfc42d Posted on: 2004-12-21 14:06 你的mysql应该是没有问题的,你用的mysql应该是4.x,换上官方的驱动可以解决 |
11.Re:高手sos!!! 连接不上mysql的问题 [Re: wilson751] | Copy to clipboard |
Posted by: wilson751 Posted on: 2004-12-21 14:23 我用的是:mysql-4.1.8-win 驱动是:mysql-connector-java-2.0.14-bin.jar 驱动存放路径:F:\tomcat4.1\common\lib\ 您知道mysql-front哪里有下载吗,多谢了 |
12.Re:高手sos!!! 连接不上mysql的问题 [Re: wilson751] | Copy to clipboard |
Posted by: 九佰 Posted on: 2004-12-21 15:04 下载地址: http://www.zdnet.de/downloads/prg/0/l/de8G0L-wc.html 运行的时候,可能缺少一个libmySQL.dll 去mysql4.1服务器的安装目录下找同名文件copy到myfront目录下即可 |
13.Re:高手sos!!! 连接不上mysql的问题 [Re: wilson751] | Copy to clipboard |
Posted by: wilson751 Posted on: 2004-12-21 15:18 试过了,用mysql-front可以连接上, 也能查出数据来 这下可麻烦了 |
14.Re:高手sos!!! 连接不上mysql的问题 [Re: wilson751] | Copy to clipboard |
Posted by: battlekiller Posted on: 2005-01-07 13:03 加栽的不对 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |