tomcat运行Jsp 出错,技术牛人请进!解决了再加100分!

来源:百度知道 编辑:UC知道 时间:2024/06/04 08:50:31
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: An exception occurred processing JSP page /index.jsp at line 4

1: <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
2: <jsp:useBean id="conn" scope="page" class="com.tools.ConnDB"/><%
3: String username=(String)session.getAttribute("username");
4: ResultSet rs_sale=conn.executeQuery("select top 3 ID,GoodsName,price,nowprice,picture,introduce from tb_goods where sale=1 order by INTime desc");
5: int sale_ID=0;
6: String s_goodsname="";
7: floa

可是这个分明就是语法错误,页面编译出错.

PreparedStatement smt = con.prepareStatement("select top 3 ID,GoodsName,price,nowprice,picture,introduce from tb_goods where sale=1 order by INTime desc");

ResultSet rs_sale=smt.executeQuery();

这么改.

[补充:]仔细读了给的源码,这个回答有错误

这是com.tools.ConnDb类中定义的一个方法

/*
*功能:执行查询语句
*/
public ResultSet executeQuery(String sql) {
try {
conn = getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(sql);
}
catch (SQLException ex) {
System.err.println(ex.getMessage());
}
return rs;
}

我上面的答案有错,这个jsp原本没有错误的,
看了Tomcat的日志才发觉:lz的错误都是数据库的配置问题.

呵呵..sorry..

你的 conn 是 Connection对象吧?
executeQuery 要 PreparedStatement 对象去调用啊 返回的才是 ResultSet对象