Can not issue empty query郁闷到何时啊?请进,谢

duanmuzi 2006-07-15 09:26:26
条件查询页面:
<html>
<body>
<center>查询书籍信息</center>
<hr size=5 color="445566">
<center>
<form action="search.jsp" method="post">
<p><input type=submit value="查询所有"></p>
</form>
<center>
<form name="form1"action=result.jsp method="post">
<p>请选择查询条件:<br>
<select name="selectedtype" size="1" >
<option value="ID">ID</option>
<option value="name">name</option>
<option value="auther">auther</option>
<option value="publisher">publisher</option>
<option value="time">time</option>
<option value="all">all</option>
</select></p>
<p>关键字<br>
<input type="text" name="keyword" size=20></p>
<p><input type=submit value=submit></p>
</form>
</center>
</body>
</html>
jsp页面:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ include file="conn1.jsp"%>
<% String id=request.getParameter("ID");
String name=request.getParameter("name");
String auther=request.getParameter("auther");
String publisher=request.getParameter("publisher");
String time1=request.getParameter("time");
String all=request.getParameter("all");
String keyword=request.getParameter("keyword");
String sql = "";
if (id!=null && id.equals("")) { sql="select * from info where ID='"+keyword+"'"; }
else if(name!=null && !name.equals("")){ sql="select * from info where name like'"+keyword+"'"; }
else if( auther!=null && auther.equals("")){ sql="select * from info where auther'"+keyword+"'"; }
else if(publisher!=null && publisher.equals("")){ sql="select * from info where publisher='"+keyword+"'"; }
else if(time1!=null && time1.equals("")) { sql="select * from info where time='"+keyword+"'"; }
else if(all!=null && all.equals("")){ sql="select * from info "; }
out.println(sql);
ResultSet rs=st.executeQuery(sql);
out.println("数据库操作成功,查询结果如下:");
out.println("<table width=50% border=3> ");
out.println("<tr><td>"+"ID"+"</td><td>"+"name"+"</td><td>"+"auther"+"</td><td>"+"publisher"+"</td><td>"+"time"+"</td></tr>");
while(rs.next()) {
String col1 =rs.getString(1);
String col2 =rs.getString(2);
String col3 =rs.getString(3);
String col4 =rs.getString(4);
String col5 =rs.getString(5);
out.println("<tr><td>"+col1+"</td><td>"+col2+"</td><td>"+col3+"</td><td>"+col4+"</td><td>"+col5+"</td></tr>");
}
out.println("</table>");
{%> <%}
%>
<%
rs.close();
st.close();
con.close();
%>
<html>
<form name="form" method="post" action="query.html">
<input type="submit" name="summit" value="返回" >
</html>
错误信息:
javax.servlet.ServletException: Can not issue empty query
弄了好久都没通,俺知道这对高手来说是小儿科,我初学,没办法阿,帮忙调一下程序,谢谢,谢谢






...全文
1187 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
duanmuzi 2006-07-15
  • 打赏
  • 举报
回复
经过努力,终于得到了正确的程序:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ include file="conn1.jsp"%>
<html>
<body>
<% String select=request.getParameter("selectedtype");
String keyword=request.getParameter("keyword");
String sql ="";
if (select.equals("ID")) { sql="select * from info where ID='"+keyword+"'"; }
else if(select.equals("name")){ sql="select * from info where name like'"+keyword+"'"; }
else if( select.equals("auther")){ sql="select * from info where auther='"+keyword+"'"; }
else if(select.equals(" publisher")){ sql="select * from info where publisher='"+keyword+"'"; }
else if(select.equals("time")) { sql="select * from info where time='"+keyword+"'"; }
else { sql="select * from info "; }
ResultSet rs=st.executeQuery(sql);
out.println("数据库操作成功,查询结果如下:");
out.println("<table width=50% border=3> ");
out.println("<tr><td>"+"ID"+"</td><td>"+"name"+"</td><td>"+"auther"+"</td><td>"+"publisher"+"</td><td>"+"time"+"</td></tr>");
while(rs.next()) {
String col1 =rs.getString(1);
String col2 =rs.getString(2);
String col3 =rs.getString(3);
String col4 =rs.getString(4);
String col5 =rs.getString(5);
out.println("<tr><td>"+col1+"</td><td>"+col2+"</td><td>"+col3+"</td><td>"+col4+"</td><td>"+col5+"</td></tr>");
}
out.println("</table>");
{%> <%}
%>
<%
rs.close();
st.close();
con.close();
%>


<form name="form" method="post" action="query.html">
<input type="submit" name="summit" value="返回" >

</form>
</body>
</html>
duanmuzi 2006-07-15
  • 打赏
  • 举报
回复
错误变了,似乎有了转机:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Exception in JSP: /result.jsp:14

11: String all=request.getParameter("all");
12: String keyword=request.getParameter("keyword");
13: String sql = "";
14: if (id!=null || !id.equals("")) { sql="select * from info where ID='"+keyword+"'"; }
15: else if(name!=null || !name.equals("")){ sql="select * from info where name like'"+keyword+"'"; }
16: else if( auther!=null || !auther.equals("")){ sql="select * from info where auther='"+keyword+"'"; }
17: else if(publisher!=null || !publisher.equals("")){ sql="select * from info where publisher='"+keyword+"'"; }


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

trumplet 2006-07-15
  • 打赏
  • 举报
回复
if (id != null && !id.equals("")) .......
?
trumplet 2006-07-15
  • 打赏
  • 举报
回复
if (id==null || id.equals("")) .......
?
trumplet 2006-07-15
  • 打赏
  • 举报
回复
你的几个条件,看不懂

if (id==null && id.equals("")) .......
?
trumplet 2006-07-15
  • 打赏
  • 举报
回复
if (id!=null && id.equals("")) .......
(和以下几个 if 里的条件)
-------------------------------

“&&” 操作法用错了吧?是不是应该用 “||”
duanmuzi 2006-07-15
  • 打赏
  • 举报
回复
有了进步,不过点击后实现的都是是全部查询,那就没有了条件的意义了阿
trumplet 2006-07-15
  • 打赏
  • 举报
回复
else if(all!=null && all.equals("")){ sql="select * from info ";}
-------------------

上边这句改一下,试试:
else { sql="select * from info ";}
kingdoom 2006-07-15
  • 打赏
  • 举报
回复
Can not issue empty query.
不能实行空查询
duanmuzi 2006-07-15
  • 打赏
  • 举报
回复
变了是这个:
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Exception in JSP: /result.jsp:21

18: else if(time1!=null && time1.equals("")) { sql="select * from info where time='"+keyword+"'"; }
19: else if(all!=null && all.equals("")){ sql="select * from info "; }
20: out.println(sql);
21: ResultSet rs=st.executeQuery(sql);
22: out.println("数据库操作成功,查询结果如下:");
23: out.println("<table width=50% border=3> ");
24: out.println("<tr><td>"+"ID"+"</td><td>"+"name"+"</td><td>"+"auther"+"</td><td>"+"publisher"+"</td><td>"+"time"+"</td></tr>");


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

javax.servlet.ServletException: Can not issue empty query.
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.result_jsp._jspService(result_jsp.java:117)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

hefei0603 2006-07-15
  • 打赏
  • 举报
回复
出错方式变了吗?
duanmuzi 2006-07-15
  • 打赏
  • 举报
回复
是 tomcat ,不过还是不行,?
trumplet 2006-07-15
  • 打赏
  • 举报
回复
是啊是啊,你的 result.jsp 里,没有 body
trumplet 2006-07-15
  • 打赏
  • 举报
回复
org.apache.jsp.result_jsp._jspService(result_jsp.java:115)
--------------------------

是 tomcat 吗?

到 %Tomcat%/work\Catalina\localhost 下边的某个子目录下,找 result_jsp.java 第115行,看它对应 result.jsp 的哪一行,再分析错误原因。
hefei0603 2006-07-15
  • 打赏
  • 举报
回复
<html>
<form name="form" method="post" action="query.html">
<input type="submit" name="summit" value="返回" >
改为
<input type="button" name="back" value="返回" onclick="location.href=query.html">
试下,没数据库很难把前面一起测试。另外把<HTML><BODY></BODY>加在适当的位置,注意要显示的内容一定要在<BODY></BODY>之间。
duanmuzi 2006-07-15
  • 打赏
  • 举报
回复
还有这些:
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Can not issue empty query.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

javax.servlet.ServletException: Can not issue empty query.
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.result_jsp._jspService(result_jsp.java:115)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

trumplet 2006-07-15
  • 打赏
  • 举报
回复
请多给出一点异常信息

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧