读书人

mysql 有关问题 java

发布时间: 2012-01-19 20:57:58 作者: rapoo

mysql 问题 java
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='2'order by book.Id desc' at line 1









...................................

}else{

sqlStr="select count(*) from book";

}

int rscount=pageSize;

try{

ResultSet rs1=stmt.executeQuery(sqlStr);

if(rs1.next())recordCount=rs1.getInt(1);

rs1.close();

}catch(SQLException e){

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

return false;





}


if(recordCount<1)

pageCount=0;

else

pageCount=(int)(recordCount-1)/pageSize+1;



if(page<1)

page=1;

else if(page>pageCount)

page=pageCount;

rscount=(int)recordCount%pageSize;



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";


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+"%'orupper(book.content)like'%"+

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

}else{

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

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

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

}

}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);

while(rs.next()){

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);

}

rs.close();

return true;

}catch(Exception e){

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

return false;

}

}


....................................................


public boolean insert() throws Exception{


[解决办法]
恩 看了下你后面的SQL语句 还有很多地方没加空格 关键字前面和后面都要跟个空格的

读书人网 >Java相关

热点推荐