<html>
<body>
<center>查询书籍信息
<hr size=5 color="445566">
<form action="search.jsp" method="post">
<p><input type=submit value="查询所有"></p>
</form>
<form action=result.jsp method="post">
<p>请选择查询条件:<br>
<select name="tiaojian" size=1>
<option values="ID">ID</option>
<option values="name">name</option>
<option values="auther">auther</option>
<option values="publisher">publisher</option>
<option values="time">time</option>
<option values="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 id1="id";
String name1="name";
String auther1="auther";
String publisher1="publisher";
String time11=" time1";
String keyword1=" keyword";
String all1="all";
if (id1==id) { String sql="select * from info where ID="+keyword; }
if(name1==name) { String sql="select * from info where name="+keyword; }
if(auther1==auther) { String sql="select * from info where auther="+keyword; }
if(publisher1==auther){ String sql="select * from info where publisher="+keyword; }
if(time11==time1) { String sql="select * from info where time="+keyword;}
if(all1==all){ String 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>
错误信息:
An error occurred at line: 5 in the jsp file: /result.jsp
Generated servlet error:
sql cannot be resolved感觉程序写的冗余代码比较多,希望大侠指点修正阿,拜谢!
<body>
<center>查询书籍信息
<hr size=5 color="445566">
<form action="search.jsp" method="post">
<p><input type=submit value="查询所有"></p>
</form>
<form action=result.jsp method="post">
<p>请选择查询条件:<br>
<select name="tiaojian" size=1>
<option values="ID">ID</option>
<option values="name">name</option>
<option values="auther">auther</option>
<option values="publisher">publisher</option>
<option values="time">time</option>
<option values="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 id1="id";
String name1="name";
String auther1="auther";
String publisher1="publisher";
String time11=" time1";
String keyword1=" keyword";
String all1="all";
if (id1==id) { String sql="select * from info where ID="+keyword; }
if(name1==name) { String sql="select * from info where name="+keyword; }
if(auther1==auther) { String sql="select * from info where auther="+keyword; }
if(publisher1==auther){ String sql="select * from info where publisher="+keyword; }
if(time11==time1) { String sql="select * from info where time="+keyword;}
if(all1==all){ String 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>
错误信息:
An error occurred at line: 5 in the jsp file: /result.jsp
Generated servlet error:
sql cannot be resolved感觉程序写的冗余代码比较多,希望大侠指点修正阿,拜谢!
解决方案 »
- 关于在CMS中使用Velocity的一点问题,请高手赐教
- 求助:struts2启动出现错误怎么解决啊??
- 如何获取本页隐藏域的值
- 图片轮刷问题
- 怎么用js控制导航!急
- 怎么样把上传流存到数据中 再从数据库中取出来 帮帮忙谢谢
- 为什么我的java web start在debug步进到jFileChooser1 = new javax.swing.JFileChooser();就自动退出了呢?
- 各位大虾谁能帮帮小弟解决一下这个函数调用问题 谢谢了
- 请问struts中的formBean如果是request的话,能够传递吗???
- 一个关闭数据库连接的问题?
- 高手帮忙看一下?(在线等)
- 简单问题:jsp定义 String 出错
if (id1==id) { sql="select * from info where ID="+keyword; }
if(name1==name) { sql="select * from info where name="+keyword; }
if(auther1==auther) { sql="select * from info where auther="+keyword; }
if(publisher1==auther){ sql="select * from info where publisher="+keyword; }
if(time11==time1) { sql="select * from info where time="+keyword;}
if(all1==all){ sql="select * from info "; }
javax.servlet.ServletException: Can not issue NULL query.
我这个程序设计的好像有问题,请指教一下