日期:2014-05-20  浏览次数:20808 次

jsp求助

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'book.bookclass='4limit0,10' at line 1
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'book.bookclass='4limit0,10' at line 1





sqlStr="select book.id,book.bookname,book.bookclass,bookclass.classname,"+

  "book.author,book.publish,book.bookno,book.content,book.prince,book.amount,"+

  "book.Leav_number,book.regtime,book.picture from book ,bookclass "+
 "where book.bookclass=bookclass.Id";
  // "where book.Bookclass=bookclass.Id";

  if(!classid.equals("")&&keyword.equals("")){

  if(page==1)

  {

  sqlStr=sqlStr+"and book.bookclass='"+classid+" order by book.Id desc" ;

  }else{

  sqlStr=sqlStr+"and book.bookclass='" + classid + "limit" (recordCount-pageSize*page)+","+(recordCount-pageSize*(page-1));

  }

  }else if(!keyword.equals("")){

  if(page==1){

  if(!classid.equals("")){

  sqlStr=sqlStr+"and book.Bookclass='"+

  classid+"'and (upper(book.bookname)like'%"+

  keyword+"%'or upper(book.content)like'%"+

  keyword+"%') order by book.Id desc";

  }else{

  sqlStr=sqlStr+"and(upper(book.bookname)like'%"+

  keyword+"%'or upper(book.content)like'%"+

  keyword+"%') order by book.Id desc";

  }

  }else{

  if(!classid.equals("")){

  sqlStr=sqlStr+"and book.Bookclass='"+

  classid+" 'and (upper(book.bookname)like'%"+

  keyword+"%'orupper(book.content)like'%"+





  keyword+"%')limit"+(recordCount-pageSize*page)+","+

  (recordCount-pageSize*(page-1));




如何修改代码

------解决方案--------------------
Java code

sqlStr="select  book.id,book.bookname,book.bookclass,bookclass.classname,"+ 

            "book.author,book.publish,book.bookno,book.content,book.prince,book.amount,"+ 

            "book.Leav_number,book.regtime,book.picture from book ,bookclass "+ 
"where book.bookclass=bookclass.Id"; 
          // "where book.Bookclass=bookclass.Id"; 

  if(!classid.equals("")&&keyword.equals("")){ 

            if(page==1) 

            { 

                  sqlStr=sqlStr+" and book.bookclass='"+classid+"' order by book.Id desc" ; 

            }else{ 

                  sqlStr=sqlStr+" and book.bookclass='" + classid + "' limit " (recordCount-pageSize*page)+","+(recordCount-pageSize*(page-1)); 

            } 

  }else if(!keyword.equals("")){ 

    if(page==1){ 

      if(!classid.equals("")){ 

          sqlStr=sqlStr+" and  book.Bookclass='"+ 

          classid+"' and (upper(book.bookname) like '%"+ 

          keyword+"%' or upper(book.content) like '%"+ 

          keyword+"%') order by book.Id desc"; 

      }else{ 

          sqlStr=sqlStr+" and (upper(book.bookname) like '%"+ 

          keyword+"%' or upper(book.content) like '%"+ 

          keyword+"%') order by book.Id desc"; 

      } 

      }else{ 

      if(!classid.equals("")){ 

            sqlStr=sqlStr+" and book.Bookclass='"+ 

            classid+"' and (upper(book.bookname) like '%"+ 

            keyword+"%' or upper(book.content) like'%"+ 


            keyword+"%') limit "+(recordCount-pageSize*page)+","+ 

            (recordCount-pageSize*(page-1));