Topic: jsp连接mysql出错!!!急急急!已经有两天了还没有弄好!!!请各位大虾帮忙

  Print this page

1.jsp连接mysql出错!!!急急急!已经有两天了还没有弄好!!!请各位大虾帮忙 Copy to clipboard
Posted by: 52dumpling
Posted on: 2005-07-24 08:40

testmysql.jsp文件代码如下:
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page language="java" import="java.sql.*"%>
<%  
java.sql.Connection conn;
java.lang.String strConn;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn= java.sql.DriverManager.getConnection("jdbc:mysql://192.168.10.2:8080/test","root","admin");
statement stmt=conn.createStatement();
ResultSet rs=null;
rs=stmt.executeQuery("select * from test");
%>
放在root目录下运行结果如下:
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 3 in the jsp file: /testmysql.jsp
Generated servlet error:
D:\Program Files\Tomcat\work\Catalina\localhost\_\org\apache\jsp\testmysql_jsp.java:50: cannot find symbol
symbol : class statement
location: class org.apache.jsp.testmysql_jsp
statement stmt=conn.createStatement();
^
1 error

说明:
我的环境变量设置:
classpath
.;D:\Program Files\jdk1.5\lib\tools.jar;D:\Program Files\jdk1.5\lib\dt.jar;D:\Program Files\Tomcat\common\lib\servlet-api.jar;D:\Program Files\Tomcat\common\lib\jsp-api.jar;D\Program Files\jdk1.5\lib\mm.mysql-2.0.4-bin.jar

path
D:\Program Files\jdk1.5\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;D:\Program Files\MySQL\bin;

JAVA_HOME
D:\Program Files\jdk1.5\bin

CATALINA_HOME
D:\Program Files\Tomcat

CATALINA_BASE
D:\Program Files\Tomcat

用javac运行helloword.java都是正常的
我还把tools.jar和dt.jar都放在tomcat\common\lib 和jdk1.5\lib目录下了
mysql的驱动文件mm.mysql-2.0.4-bin.jar我也同时放在上面两个目录下了
我安装的是jdk1.5+mysql4.1+tomcat5.0.28

2.Re:jsp连接mysql出错!!!急急急!已经有两天了还没有弄好!!!请各位大虾帮忙 [Re: 52dumpling] Copy to clipboard
Posted by: jimmy14
Posted on: 2005-07-24 09:39

Statement stmt=conn.createStatement();

3.Re:jsp连接mysql出错!!!还是出错啊!!! [Re: 52dumpling] Copy to clipboard
Posted by: 52dumpling
Posted on: 2005-07-24 10:04

谢谢楼上的高手指点:
将statement stmt=conn.createStatement();
已经改为
Statement stmt=conn.createStatement();

但是还是出错了;信息如下:
type Exception report

message

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

exception

javax.servlet.ServletException: Communication link failure: java.io.EOFException
  org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
  org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
  org.apache.jsp.testmysql_jsp._jspService(testmysql_jsp.java:61)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

java.sql.SQLException: Communication link failure: java.io.EOFException
  org.gjt.mm.mysql.MysqlIO.init(MysqlIO.java:370)
  org.gjt.mm.mysql.Connection.connectionInit(Connection.java:261)
  org.gjt.mm.mysql.jdbc2.Connection.connectionInit(Connection.java:89)
  org.gjt.mm.mysql.Driver.connect(Driver.java:167)
  java.sql.DriverManager.getConnection(Unknown Source)
  java.sql.DriverManager.getConnection(Unknown Source)
  org.apache.jsp.testmysql_jsp._jspService(testmysql_jsp.java:49)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

请指点!!!!
为谢!1

4.Re:jsp连接mysql出错!!!还是出错啊!!! [Re: 52dumpling] Copy to clipboard
Posted by: jimmy14
Posted on: 2005-07-24 13:26

post your whole testmysql.jsp, show how did you read data.

5.Re:jsp连接mysql出错!!!还是出错啊!!! [Re: jimmy14] Copy to clipboard
Posted by: 52dumpling
Posted on: 2005-07-24 15:01

testmysql.jsp文件代码如下:
是从网上down 下来的原文件

<%@ page contentType="text/html;charset=GB2312" %>
<%@ page language="java" import="java.sql.*"%>
<%
java.sql.Connection conn;
java.lang.String strConn;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn= java.sql.DriverManager.getConnection("jdbc:mysql://192.168.10.2:8080/test","root","admin");
statement stmt=conn.createStatement();
ResultSet rs=null;
rs=stmt.executeQuery("select * from test");
%>

是按照网上的步骤安装开发环境的,然后就是到了这里testmysql.jsp出了问题了

6.Re:jsp连接mysql出错!!!还是出错啊!!! [Re: jimmy14] Copy to clipboard
Posted by: sylilzy
Posted on: 2005-07-24 15:45

不知你的mysql是什么版本,不过最好不要用旧版的mysql驱动:org.gjt.mm.mysql.Driver,去mysql的网站下最新的驱动mysql-connector-java-3.1.6.zip,用com.mysql.jdbc.Driver连接应该没问题

7.Re:jsp连接mysql出错!!!急急急!已经有两天了还没有弄好!!!请各位大虾帮忙 [Re: 52dumpling] Copy to clipboard
Posted by: sylilzy
Posted on: 2005-07-24 15:47

不好意思,刚才没仔细看你的程序,其中:
conn= java.sql.DriverManager.getConnection("jdbc:mysql://192.168.10.2:8080/test","root","admin");
你应该连接数据库的某个端口,比如:jdbc:mysql://localhost:3306/testdb

8.Re:jsp连接mysql出错!!!急急急!已经有两天了还没有弄好!!!请各位大虾帮忙 [Re: 52dumpling] Copy to clipboard
Posted by: sylilzy
Posted on: 2005-07-24 15:48

如果有问题与我联系:sylilzy@163.com

9.Re:jsp连接mysql出错!!!急急急!已经有两天了还没有弄好!!!请各位大虾帮忙 [Re: sylilzy] Copy to clipboard
Posted by: 52dumpling
Posted on: 2005-07-24 17:10

谢谢大侠指点。问题已经解决了!!!

10.Re:jsp连接mysql出错!!!急急急!已经有两天了还没有弄好!!!请各位大虾帮忙 [Re: 52dumpling] Copy to clipboard
Posted by: chengbd
Posted on: 2005-07-28 12:31

52dumpling,这么多人,说了这么多与你交流。如果你只以“问题已经解决了!!!”作为最后的总结,是不是太简单了,如果别人也这样回答你,让你自己去调试,你的感受如何?
不妨也花费些您的时间,把你解决问题的过程,和问题到底出在哪写出来吧。虽然你也许会觉得这个问题解决的很弱智,不过这样才是更好的交流。

11.Re:jsp连接mysql出错!!!急急急!已经有两天了还没有弄好!!!请各位大虾帮忙 [Re: 52dumpling] Copy to clipboard
Posted by: 52dumpling
Posted on: 2005-07-28 18:59

谢谢楼上的高手指点。真是一语惊醒梦中人。现在才明白任何细小的问题都要认真去对待,努力寻找解决问题的解决方法才能学到知识。

现在将我解决问题的过程介绍如下:
1、第一次按照网上介绍的方法配置后(具体配置及测试文件见顶部帖子),出现以下问题:
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 3 in the jsp file: /testmysql.jsp
Generated servlet error:
D:\Program Files\Tomcat\work\Catalina\localhost\_\org\apache\jsp\testmysql_jsp.java:50: cannot find symbol
symbol : class statement
location: class org.apache.jsp.testmysql_jsp
statement stmt=conn.createStatement();
^
1 error

后来是jimmy14 指点:
将statement stmt=conn.createStatement();
改为Statement stmt=conn.createStatement();

接着又出现如下问题:
java.sql.SQLException: Communication link failure: java.io.EOFException
org.gjt.mm.mysql.MysqlIO.init(MysqlIO.java:370)
org.gjt.mm.mysql.Connection.connectionInit(Connection.java:261)
org.gjt.mm.mysql.jdbc2.Connection.connectionInit(Connection.java:89)
org.gjt.mm.mysql.Driver.connect(Driver.java:167)
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
org.apache.jsp.testmysql_jsp._jspService(testmysql_jsp.java:49)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

按照上面错误的信息来看应该是数据库驱动连接问题
以前的老版本驱动文件mm.mysql-2.0.4-bin.jar已经不适合了,就下载了新的驱动文件:mysql-connector-java-3.1.10-bin.jar 安装后问题才得以解决。

还有一点要说明的就是:网上好多测试文章、配置文章不能完全ctrl+c ctrl+v
必须认认真真的看清楚,里面包含空格、大小写问题、端口问题等等都需要修改的。

在此我要感谢楼上各位的帮助和指点。希望以后能够跟大家一起学习交流。

12.Re:jsp连接mysql出错!!!急急急!已经有两天了还没有弄好!!!请各位大虾帮忙 [Re: 52dumpling] Copy to clipboard
Posted by: 52dumpling
Posted on: 2005-07-28 19:21

学习jsp已经有几天了,现在将我这几天的学习笔记总结如下:

2005年7月24-26日最终设置,运行成功

环境:winxp+jdk1.5+tomcat5.0.28+mysql4.1

说明:
1、安装jdk1.5
2、安装tomcat5.0.28
3、安装mysql4.1
4、配置环境变量(具体如下)
说明:(1、tools.jar和dt.jar均放在tomcat\common\lib下 和jdk1.5\lib下;2、mysql的驱动文件也要同时放在上面两个目录下)

classpath
.;D:\Program Files\jdk1.5\lib\tools.jar;D:\Program Files\jdk1.5\lib\dt.jar;D:\Program Files\Tomcat\common\lib\servlet-api.jar;D:\Program Files\Tomcat\common\lib\jsp-api.jar;D\Program Files\jdk1.5\lib\mm.mysql-2.0.4-bin.jar

path
D:\Program Files\jdk1.5\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;D:\Program Files\MySQL\bin;

JAVA_HOME
D:\Program Files\jdk1.5\bin

CATALINA_HOME
D:\Program Files\Tomcat

CATALINA_BASE
D:\Program Files\Tomcat

**********************************************************
classpath增加部分2005.07.25 (mssql2000的jdbc驱动)
在用jsp连接mssql2000测试的时候,出现的问题最多。由于当时没有将问题收录下来,在网上搜索了很多文章才解决的。现在将经验总结如下:

1、断掉网络,先安装mssql 2000 + mssql 2000的jdbc驱动 + mssql 2000的补丁spk3 + mssql 2000的jdbcjdbc驱动的补丁spk
2、找到jdbc驱动文件安装目录下的msutil.jar,msbase.jar,mssqlerver.jar三个文件并分别放在tomcat\common\lib和jdk1.5\lib下面。
3、加入环境变量,重新启动电脑,

我的电脑最终完整的classpath如下(包含mysql及sql2000的驱动程序):

.;D:\Program Files\jdk1.5\lib\tools.jar;
D:\Program Files\jdk1.5\lib\dt.jar;
D:\Program Files\Tomcat\common\lib\servlet-api.jar;
D:\Program Files\Tomcat\common\lib\jsp-api.jar;
D\Program Files\jdk1.5\lib\mysql-connector-java-3.1.10-bin.jar;
D\Program Files\tomcat\common\lib\mysql-connector-java-3.1.10-bin.jar;
D:\Program Files\tomcat\common\lib\msutil.jar;
D:\Program Files\tomcat\common\lib\msbase.jar;
D:\Program Files\tomcat\common\lib\mssqlerver.jar

**********************************************************
测试文件:
1、testmysql.jsp
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page language="java" import="java.sql.*"%>
<%
java.sql.Connection conn;
java.lang.String strConn;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn= java.sql.DriverManager.getConnection("jdbc:mysql://192.168.10.2:3306/mysql","root","admin");
Statement stmt=conn.createStatement();
ResultSet rs=null;
rs=stmt.executeQuery("select * from user");
%>

2、testmssql.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.io.*"%>
<html>
<body>
<% Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://192.168.10.2:1433;DatabaseName=pubs";
String user="sa";
String password="admin";
Connection conn=DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select job_id,job_desc from jobs";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){%>
您的第一个字段内容为:<%=rs.getString(1)%><br>
您的第二个字段内容为:<%=rs.getString(2)%><br>
<%}%>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>

以上两个文件都测试通过。
另外,为了方便学习,我从网上下载了不少工具及文件,详细清单如下:
一、JDK
1、j2sdk-1_4_2-windows-i586.exe 42.7M
2、j2sdk1.4.2.exe 52.2M
3、jdk1.5.exe 43.9M
4、jdk-1_5_0_02-nb-4_0-ml-win.exe 102M

二、Tomcat服务器
1、jakarta-tomcat-5.0.28.exe 10M
2、jakarta-tomcat-5.0.30.exe 10.2M
3、jakarta-tomcat-5.5.9.exe 4.29M

三、jboss服务器
jboss-4.0.2.tar.gz

四、mysql数据库及客户端工具
1、mysql-4.0.25-win32.zip 25.1M
2、mysql-4.1.13-win32.zip 37.7M
3、mysql-5.0.9-beta-win32.zip 42M
4、phpmyadmin2.6.0_final.rar 1.04M
5、MySQL-Front_2.5_Setup.exe 1.02M
6、mysql-administrator-1.1.0-rc-win-noinstall.zip 4.21M
7、mysql-query-browser-1.1.13-win-noinstall.zip 4.73M

五、数据库驱动文件
1、mysql-connector-java-3.1.10.zip 6.69M
2、mm.mysql-2.0.4-bin.jar 107K
3、mssql2000 jdbcsetup.exe 1.99M
4、mssql2000 jdbc驱动spk3 2.29M

六、插件
1、tomcatPluginV3.zip
2、lomboz-3.1M6.zip

如有需要,可以与我联系
QQ:106634458 e-mail:iszx@163.com


   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