只为一世逍遥 2015-04-11 23:53 采纳率: 0%
浏览 2498

jsp 连接 mysql 查询 报错500

源代码:
<%@ page contentType="text/html; charset=GB2312"%>
<%@ page import="java.util.*,java.sql.*"%>
<%
request.setCharacterEncoding("GB2312");
//链接数据库程序
Class.forName("org.gjt.mm.mysql.Driver");
//Connection conn = DriverManager.getConnection( -------SQL桥
// "jdbc:odbc:bookshoplk", "sa", "");
Connection connect = DriverManager
.getConnection("jdbc:mysql://localhost:3306/bookshop?user=root&password=root&useUnicode=true&characterEncoding=GBK");
//Statement stmt = conn.createStatement( ---------- SQL的连接
// ResultSet.TYPE_SCROLL_INSENSITIVE,
// ResultSet.CONCUR_READ_ONLY);
Statement stmt = connect.createStatement();
ResultSet rs = null;
//rs结果集
String s_where = (String) session.getAttribute("s_where");
String s_bookid = "";
String s_bookname = "";
String s_author = "";
String s_publisher = "";
String s_price = "";
int i_totalnum = 0;//书籍数量
rs = stmt //String sql=“SELECT * FROM show
.executeQuery("select count(distinct bookid) from'book left join publisher on book.publisherid=publisher.publisherid where bookid is not null "
+ s_where);
rs.next();
i_totalnum = rs.getInt(1);
%>
<%
if (i_totalnum != 0) {//显示的是查询结果
%>

书号 书名 作者 出版社 价格

<%
} else {
String temp = "没有您要找的书,请重新搜索!返回。";
temp = java.net.URLEncoder.encode(temp.toString(), "gbk");
response.sendRedirect("error.jsp?error=" + temp);
//显示,为查询到结果
%>

<%
}
%>

错误提;

type Exception report

message An exception occurred processing JSP page /cust/booklist.jsp at line 25

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 /cust/booklist.jsp at line 25

22: String s_price = "";
23: int i_totalnum = 0;//�鼮����
24: rs = stmt //String sql=��SELECT * FROM show��
25: .executeQuery("select count(distinct bookid) from'book left join publisher on book.publisherid=publisher.publisherid where bookid is not null "
26: + s_where);
27: rs.next();
28: i_totalnum = rs.getInt(1);

Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:567)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:454)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

javax.servlet.ServletException: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''book left join publisher on book.publisherid=publisher.publisherid where booki' at line 1
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:908)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:837)
org.apache.jsp.cust.booklist_jsp._jspService(booklist_jsp.java:220)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:431)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''book left join publisher on book.publisherid=publisher.publisherid where booki' at line 1
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
com.mysql.jdbc.Connection.execSQL(Connection.java:3206)
com.mysql.jdbc.Statement.executeQuery(Statement.java:1232)
org.apache.jsp.cust.booklist_jsp._jspService(booklist_jsp.java:117)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:431)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/8.0.20 logs.

  • 写回答

1条回答 默认 最新

  • danielinbiti 2015-04-12 00:48
    关注
     25: .executeQuery("select count(distinct bookid) from'book left join publisher on book.publisherid=publisher.publisherid where bookid is not null "   
     form和book之间多了一个单引号
    
    评论

报告相同问题?

悬赏问题

  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档