2 u012903563 u012903563 于 2014.01.02 18:43 提问

jsp中模糊查询,后台没有出错,为什么实现不了?

点击查找只是刷新页面,后台没有问题,但是又实现不了
具体代码:
<% request.setCharacterEncoding("utf-8"); %>

<%!
private static final String DBDRIVER ="org.gjt.mm.mysql.Driver";
private static final String DBURL ="jdbc:mysql://localhost:3306/tushu";
private static final String DBUSER = "root";
private static final String DBPASSWORD ="admin";

%>
<%
Connection conn =null;
PreparedStatement pstmt =null;
ResultSet rs =null;
%>
<%
int pageCount = 5;//每页显示行数
int rowCount = 0;//总记录数
int currentPage = 1;//当前页码
int sumPageCount = 0;//总的页数
int currentRow = 1;

%>

<%
String word=null;
String strPage = request.getParameter("page");

if(word!=null){
word=new String(request.getParameter("key").getBytes("ISO-8859-1"),"utf-8");

word = request.getParameter("key");

}
if(strPage==null){
currentPage = 1;
}else{
currentPage = Integer.parseInt(strPage);
}
%>

<%
try{
Class.forName(DBDRIVER);
conn = DriverManager.getConnection(DBURL, DBUSER, DBPASSWORD);
String sql = null;
if(word==null){
sql = "select b_ID,b_Name,b_Author,b_Translator,chub,b_Price,b_Quantity from bookinfo";
pstmt = conn.prepareStatement(sql);
}else{
sql = "select b_ID,b_Name,b_Author,b_Translator,chub,b_Price,b_Quantity from bookinfo where"+" b_Name like '%''+word+''%'"+" or b_Author like '%''+word+''%'";

    pstmt.setString(1,"%"+word+"%");
    pstmt.setString(2,"%"+word+"%");
}
rs = pstmt.executeQuery();
rs.last();
rowCount = rs.getRow();
if(rowCount % pageCount == 0){
    sumPageCount = rowCount/pageCount;
}else{
    sumPageCount = rowCount/pageCount + 1;
}
currentRow = (currentPage-1)*pageCount+1;
rs.absolute(currentRow);

%>




输入要查询的内容:


"/>


共检索到:个记录,分页显示,现在显示的是第页


编号 名称 作者 译者 出版社 价格(¥) 副本数 修改图书 删除图书
修改图书 删除图书
下一页 下一页 1){ if(word!=null){ %> 上一页 下一页

<%
}catch(Exception e){

System.out.println(e);

}finally{
rs.close();
pstmt.close();
conn.close();
}
%>

Csdn user default icon
上传中...
上传图片
插入图片