<html> 
 <script language="javascript">
function selectedtype_onchange(){
var i=form1.selectedtype.options.selectedIndex;
form1.selectedtype.value=form1.selectedtype.options[i].value;
form1.submit();
}
</script>
<body> 
<center>查询书籍信息</center>
<hr size=5 color="445566">
<center>
<form action="search.jsp"  method="post"> 
<p><input type=submit value="查询所有"></p> 
</form> 
<center>
<form action=result.jsp  method="post"> 
 <p>请选择查询条件:<br> 
 <select name="selectedtype" size="1" LANGUAGE=javascript onchange="return tradetype_onchange()"> 
    <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>
</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!="")  {  sql="select * from info where ID='"+keyword+"'";   }
   if(name!=null && name!="")  { sql="select * from info where namelike'"+keyword+"'";   }
   if(auther!=null && auther!="") { sql="select * from info where auther'"+keyword+"'";     }
   if(publisher!=null && publisher!=""){ sql="select * from info where  publisher='"+keyword+"'";   }
   if(time1!=null && time1!="") { sql="select * from info where time='"+keyword+"'";    }
   if(all!=null && all!=""){   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(); 
%>                   
<html>
<form  name="form" method="post" action="query.html">
      <input type="submit" name="summit" value="返回" >
</html>
错误信息:
javax.servlet.ServletException: Can not issue empty query.
搞了好久了,没弄通,是为什么?拜谢!

解决方案 »

  1.   

    ResultSet rs=st.executeQuery(sql); 这句之前加一个打印语句System.out.println(sql);估计你的sql=""传入查询了
      

  2.   

    倒~~就是让你看一下后台的sql打印出来是什么
      

  3.   

    看看你都写了什么:if (id!=null && id!="") {……}字符串比较要用equals!!!!!!!!!!!!!!!!!!
      

  4.   

    所有的都要该,你现在的一大堆判断没有一个执行到内部!if (id!=null && id.equals("")){……}
      

  5.   

    if (id!=null && !id.equals("")){……}