标题:[求助]jsp与mysql数据库!
只看楼主
wenbin171
Rank: 1
等 级:新手上路
帖 子:119
专家分:0
注 册:2007-11-6
 问题点数:0 回复次数:3 
[求助]jsp与mysql数据库!
代码如下:

<%@ page contentType="text/html; charset=gb2312" %>

<%@ page language="java" %>

<%@ page import="com.mysql.jdbc.Driver" %>

<%@ page import="java.sql.*" %>

<%

//驱动程序名

String driverName="com.mysql.jdbc.Driver";

//数据库用户名

String userName="root";

//密码

String userPasswd="wenbin";

//数据库名

String dbName="first";

//表名

String tableName="about";

//联结字符串

String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;

Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection connection=DriverManager.getConnection(url);

Statement statement = connection.createStatement();

String sql="SELECT * FROM "+tableName;

ResultSet rs = statement.executeQuery(sql);

//获得数据结果集合

ResultSetMetaData rmeta = rs.getMetaData();

//确定数据集的列数,亦字段数

int numColumns=rmeta.getColumnCount();

// 输出每一个数据值

out.print("id");

out.print("|");

out.print("num");

out.print("<br>");

while(rs.next()) {

out.print(rs.getString(1)+" ");

out.print("|");

out.print(rs.getString(2));

out.print("<br>");

}

out.print("<br>");

out.print("数据库操作成功,恭喜你");

rs.close();

statement.close();

connection.close();

%>


//以上代码有错吗?运行起来总报错:

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: Unable to compile class for JSP:


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.


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

Apache Tomcat/6.0.10



//各位,请帮忙看看!先谢谢了!
搜索更多相关主题的帖子: jsp 数据库 mysql 
2007-11-06 15:57
wenbin171
Rank: 1
等 级:新手上路
帖 子:119
专家分:0
注 册:2007-11-6
得分:0 
会的人来顶一下好吗?

-------哼!谁说不可以-------
2007-11-06 16:02
woody3221
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2006-11-14
得分:0 
我不会,帮你顶一下

我要好好学习,天天向上!
2007-11-06 16:15
huidongg
Rank: 1
等 级:禁止访问
帖 子:3
专家分:0
注 册:2007-11-6
得分:0 
提示: 作者被禁止或删除 内容自动屏蔽
2007-11-06 16:57



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-183946-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.417449 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved