linux 下用 eclipse 开发 JSP 连接 MySQL 报错 500 提示查询语句处有问题
我用原来的查SQL 的查询语句直接上Mysql
数据库已经连接上了,测试过
这是源代码:
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="java.util.*,java.sql.*"%>
<%
request.setCharacterEncoding("GBK");
//链接数据库程序
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.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
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;//book number
rs = stmt
.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) {//显示的是查询结果
%>
<table border=1>
<tr>
<td width=30%>书号</td>
<td width=30%>书名</td>
<td width=10%>作者</td>
<td width=15%>出版社</td>
<td width=30%>价格</td>
</tr>
<%
rs= stmt
.executeQuery("select * from book left join publisher on book.publisherid=publisher.publisherid where bookid is not null "
+ s_where + " order by bookid ");
for (int i = 0; i <= i_totalnum; i++) {
if (!rs.isLast()) {
rs.next();
s_bookid = rs.getString("bookid");
s_bookname = rs.getString("bookname");
s_author = rs.getString("author");
s_price = rs.getString("price");
s_publisher = rs.getString("name");
%>
<tr>
<td><%=s_bookid%></td>
<td><%=s_bookname%></td>
<td><%=s_author%></td>
<td><%=s_publisher%></td>
<td><%=s_price%></td>
</tr>
<%
}
}
%>
</table>
<%
} else {
String temp = "没有您要找的书,请重新搜索!返回。";
temp = java.net.URLEncoder.encode(temp.toString(), "gbk");
response.sendRedirect("error.jsp?error=" + temp);
//显示,为查询到结果
%>
<!-- ---
<table>
<tr>
<td>
<img src="../img/sorry.jpeg" />
</td>
</tr>
<tr>
<td>
没有您要找的书,请
<a href="search.jsp">重新搜索</a>
</td>
</tr>
</table>
-->
<%
}
%>
这是错误提示:
type Exception report
message An exception occurred processing JSP page /cust/booklist.jsp at line 28
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 28
25: int i_totalnum = 0;//book number
26:
27: rs = stmt
28: .executeQuery("select count(distinct bookid) from book left join publisher on book.publisherid=publisher.publisherid where bookid is not null "
29: + s_where);
30: rs.next();
31: 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: Unknown column 'book.publisherid' in 'on clause'
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:224)
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: Unknown column 'book.publisherid' in 'on clause'
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:120)
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.