请问下在java中执行sql语句,为什么每次读到limit就会直接跳过?

public List queryAll(int currentPage, int lineSize) throws Exception {
List<Note> all = new ArrayList<Note>() ;
String sql = " select id,title,author,content from note limit (" + ((currentPage-1)*lineSize) + "," + lineSize + ")" ;
PreparedStatement pstmt = null ;
try {
pstmt = this.dbc.getConnection().prepareStatement(sql) ; // 每次执行到这里就会直接finally了。请问这是为什么
ResultSet rSet = pstmt.executeQuery() ;

while(rSet.next()){
Note note = new Note() ;
note.setId(rSet.getInt(1)) ;
note.setTitle(rSet.getString(2)) ;
note.setAuthor(rSet.getString(3)) ;
note.setContent(rSet.getString(4)) ;
all.add(note) ;
}
rSet.close() ;
pstmt.close() ;
} catch (Exception e) {
// TODO: handle exception
}
finally{
dbc.close() ;
}
return all;
}

紫衣仙女
浏览 167回答 2
2回答

慕运维8079593

如果我没看错的话应该是sql语法错了 limit后边是不应该有括号的 应该是这样select * from table limit 0,100

一只萌萌小番薯

String sql = " select id,title,author,content from note limit (" + ((currentPage-1)*lineSize) + "," + lineSize + ")" ;是 SQL语句吗? 是不是你写错了。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java
SQL Server