首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

代码有错

2012-01-30 
求助代码有错You have an error in your SQL syntax check the manual that corresponds to your MySQL s

求助 代码有错
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 'where book.bookclass=bookclass.Id order by book.Id desc limit 0, 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.picturefrombook ,bookclass "+
 "where book.bookclass=bookclass.Id";
  if(!classid.equals("")&&keyword.equals("")){

  if(page==1)

  {

  sqlStr=sqlStr+"andbook.bookclass='"+classid+"'"+

  "orderbybook.Iddesc";

  }else{

  sqlStr=sqlStr+"andbook.bookclass='"+classid+"limit"+

  (recordCount-pageSize*page)+","+(recordCount-pageSize*(page-

1));

  }

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

  if(page==1){

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

  sqlStr=sqlStr+"andbook.Bookclass='"+

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

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

  keyword+"%') orderbybook.Iddesc";

  }else{

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

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

  keyword+"%')orderbybook.Iddesc";

  }

  }else{

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

  sqlStr=sqlStr+"andbook.Bookclass='"+

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

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





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

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

  }else{

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

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

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

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

  }

  }

}else{

  if(page==1){
  // sqlStr=sqlStr+" order by book.id desc limit 0,"+pageSize;
  // sqlStr=sqlStr+" order by Id desc "+pageSize;
  sqlStr=sqlStr+" order by book.Id desc limit 0, "+pageSize;

  }else{

  sqlStr=sqlStr+"limit"+(recordCount-pageSize*page)+","+

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

  }

  }

  try {

  rs=stmt.executeQuery(sqlStr);

  booklist=new Vector(rscount);

  。。。。。。。。。。。。。。。。。。
。。。。。。。。。。。。。。。。。。。。。。。。。。 }

  rs.close();

  return true;

  }catch(Exception e){

  System.out.println(e.getMessage());



  return false;

  }

  }





 public boolean insert() throws Exception{

  。。。。。。。。。。。。。。。。。。。。。。。。。
。。。。。。。。。。。。。。。。。。。。

  }



  }



  public boolean delete(int aid) throws Exception{

  sqlStr="delete from book where id=" +aid;

  try

  { DataBase db=new DataBase();

  db.connect();

  stmt=db.conn.createStatement();

  stmt.execute(sqlStr);

  return true;

  }

  catch(SQLException e)

  {

  System.out.println(e);

  return false;

  }

  }


public boolean getOnebook(int newid) throws Exception{

  DataBase db=new DataBase();

  db.connect();

  stmt=db.conn.createStatement();

  try{

  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.picturefrombook ,bookclass where book.Bookclass="+

  "bookclass.Id and book.Id="+newid;

  rs=stmt.executeQuery(sqlStr);

  if(rs.next())

  { booklist=new Vector(1);

  book book=new book();

  book.setId(rs.getLong("id"));

  book.setBookName(rs.getString("bookname"));

  book.setBookClass(rs.getInt("bookclass"));

  book.setClassname(rs.getString("classname"));

  book.setAuthor(rs.getString("author"));

  book.setPublish(rs.getString("publish"));

  book.setBookNo(rs.getString("Bookno"));

  book.setContent(rs.getString("content"));

  book.setPrince(rs.getFloat("prince"));

  book.setAmount(rs.getInt("amount"));

  book.setLeav_number(rs.getInt("leav_number"));

  book.setRegTime(rs.getString("regtime"));

  book.setPicture(rs.getString("picture"));

  booklist.addElement(book);

  }else{

  rs.close();

  return false;

  }

  rs.close();

  return true;

  }



  catch(SQLException e)

  {

  return false;

  }

  }

   
}





[解决办法]
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.picturefrombook ,bookclass "+ 
"where book.bookclass=bookclass.Id";这个SQL语句有错 怎么没有看到from这个关键字 你要从哪张表里面查数据啊就要加上from哪张表

热点排行