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个回答

 25: .executeQuery("select count(distinct bookid) from'book left join publisher on book.publisherid=publisher.publisherid where bookid is not null "   
 form和book之间多了一个单引号
u010815558
只为一世逍遥 回复danielinbiti: 我弄好了,是我数据库里面的子项名字打错了.始终报错,谢谢你了
4 年多之前 回复
u010815558
只为一世逍遥 回复danielinbiti: 偶偶,我去试试
4 年多之前 回复
danielinbiti
danielinbiti 回复u010815558: 你最好把这句完整的SQL打印出来,放到客户端执行一下,先看客户端能不能执行。看是不是缺东西。
4 年多之前 回复
u010815558
只为一世逍遥 回复danielinbiti: 谢谢你了
4 年多之前 回复
u010815558
只为一世逍遥 回复danielinbiti: 帮我看看这个,http://bbs.csdn.net/topics/391015469这个铁就是我发的有全部的内容,这些代码是我从连接SQl数据库拔下来的,我把连接桥改了,连接mysql
4 年多之前 回复
danielinbiti
danielinbiti 回复u010815558: 看看select count(distinct bookid) from'book left join publisher on book.publisherid=publisher.publisherid where bookid is not null " + s_where,这里面的s_where是什么,有没有多where或者少and,拼上后在数据库客户端中能不能直接查询
4 年多之前 回复
u010815558
只为一世逍遥 引号去掉还是报错
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!