oracle,mysql真分頁

又到了畢設的季節,有位同窗問我真分頁的問題,就寫個例子參考參考吧mysql

oracle語句使用ROWNUM真分頁sql

sql = "select * from ( select pid,name,price,amount,ROWNUM rn from product where ( name LIKE ? or price LIKE ? or amount LIKE ? ) AND ROWNUM < = ? order by pid ) temp where temp.rn > ?oracle

pstmt = conn.prepareStatement(sql);ide

pstmt.setString(1,"%"+keyword+"%");this

pstmt.setString(2,"%"+keyword+"%");it

pstmt.setString(3,"%"+keyword+"%");class

pstmt.setString(4,"%"+keyword+"%");select

pstmt.setInt(5,"%"+keyword+"%");分頁

pstmt.setInt(6,"%"+keyword+"%");im

rs = pstmt.executeQuery();

相應的mysql真分頁寫法(用limit)

String sql = "select * from product where name like ? or note like ? or price like ? or amount like ? order by pid LIMIT ?,?"

this.pstmt = conn.prepareStatement(sql);

this.pstmt.setString(1,"%"+keyword+"%");

this.pstmt.setString(2,"%"+keyword+"%");

this.pstmt.setString(3,"%"+keyword+"%");

this.pstmt.setString(4,"%"+keyword+"%");

this.pstmt.setInt(5,(currentPage-1)*linesize);

this.pstmt.setInt(6,linesize);

ResultSet rs = pstmt.executeQuery();

相關文章
相關標籤/搜索