package store . dao ;
//省略包导入代码
public class CategoryDAO (
public List < Category > findCategories ( String name , Pager pager ) throws
Exception {
List < Category > list = new ArrayList <>();
Connection con = null ;
PreparedStatement ps = null ;
ResultSet rs = null ;
try {
Class . forName ( DB . JDBC _ DRIVER );
con = DriverManager . getConnection ( DB . JDBC _ URL , DB . JDBC _ USER ,
ps = con . prepareStatement (” select count ( id ) as total from t _ category
ps . setString (1,”%”+ name +”%”);
rs = ps . executeQuery ();
if ( rs . next ()){
DB . JDBC _ PASSWORD );
where name like ?”);
pager . setTotal ( rs . getInt (” total “));
(
ps = con . prepareStatement (” select * from t _ category where name
like ? limit ?,?”);
ps . setString (1,”%”+ name +”%”);
ps . setInt (2,( pager . getCurrentPage ()-1)* pager . getPageSize ());
ps . setInt (3, pager . getPageSize ());
rs = ps . executeQuery ();
while ( rs . next ())(
Category c = new Category ();
c . setId ( rs . getInt (” id “));
c . setName ( rs . getString (” name “));
c . setDescription ( rs . getString (” description “));
list . add ( c );
) catch ( Exception e ){
e . printStackTrace ();
throw new Exception (“数据库异常:”+ e . getMessage ());
原文地址:https://blog.csdn.net/lllzhou/article/details/134637111
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_6651.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!