一个关于jsp中的sql 语句 like 的问题急等解决!!!!!!

springleaves 2002-05-05 11:32:11
我有一段程序是关于 jsp中的sql语句的
程序如下<%
String getPage=request.getParameter("pageId").trim();
if(getPage.compareTo("-1")==0)
{
//分页准备工作,保存分页信息
Page myPage=new Page();
String bookname=request.getParamer("bookname").trim();
String author=request.getParameter("author").trim();
String nameSelect="";
String authorSelect="";
if(bookname.compareTo("")!=0) nameSelect="bookname like '%"+bookname+"%'";
if(author.compareTo("")!=0) authorSelect="author like '%"+author+"%'";

byte[] tmpbyte=nameSelect.getBytes("ISO8859_1");
nameSelect=new String(tmpbyte);
tmpbyte=authorSelect.getBytes("ISO8859_1");
authorSelect=new String(tmpbyte);

if(authorSelect.compareTo("")!=0&&nameSelect.compareTo("")!=0)
nameSelect=" and "+nameSelect;
String sql="select pid from book where";
sql=sql+authorSelect+nameSelect+" order by pid desc";
//sql是生成的查询语句
session.putValue("authorSelect",authorSelect);
session.putValue("nameSelect",nameSelect);
ResultSet rs=db.executeQuery(sql);

myPage.recordCount=0;
myPage.pageSize=10;
myPage.pageCount=0;
myPage.pageId=1;

Vector idList=new Vector();
getPage="1";
while(rs.next())
{
myPage.recordCount++;
if(myPage.recordCount==myPage.pageSize)
{
myPage.pageCount++;
idList.addElement(rs.getString("pid"));
myPage.recordCount=0;
}
}

if(myPage.recordCount!=0)
myPage.pageCount++;
myPage.recordCount+=(myPage.pageCount-1)*myPage.pageSize;
rs.close();
session.putValue("idList",idList);
session.putValue("myPage",myPage);
}
%>

但是运行时,总是报错, 说是在 like 关键字附近有语法错误但我找不出哪位高手请帮忙!!!
...全文
52 点赞 收藏 2
写回复
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
springleaves 2002-05-05
感谢realyfly(含泪海)帮助,问题已经解决了以后多多帮助!!!谢谢谢谢!!!
回复
可乐加水 2002-05-05
nameSelect="bookname like '%"+bookname+"%'";
if(author.compareTo("")!=0) authorSelect="author like '%"+author+"%'";
改成这样
nameSelect=" bookname like '%"+bookname+"%'";
if(author.compareTo("")!=0) authorSelect=" author like '%"+author+"%'";
在两个语句的前面个加一个空格,应该可以了
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告