idea 中的接口
package cn.bdqn.dao;
import cn.bdqn.entity.employee;
import java.sql.SQLException;
import java.util.List;
/**
* Created by linlin on 2017/6/16.
*/
public interface empdao {
public List<employee> selectemp(int pageindex,int pagesize)throws Exception;
public int getCount() throws SQLException;
}
实现类
package cn.bdqn.service;
import cn.bdqn.dao.empdao;
import cn.bdqn.entity.employee;
import cn.bdqn.util.BaseDAO;
import org.junit.Test;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* Created by linlin on 2017/6/16.
*/
public class empservice extends BaseDAO implements empdao {
public List<employee> selectemp(int pageindex,int pagesize) throws Exception {
List<employee> list=new ArrayList<employee>();
String sql="select * from employee limit ?,?";
ResultSet rs=executeQuery(sql,pageindex,pagesize);
if(rs!=null){
while(rs.next()){
employee emp=new employee();
emp.setName(rs.getString("name"));
emp.setSalary(rs.getDouble("salary"));
emp.setDepartment_id(rs.getInt("department_id"));
emp.setPassword(rs.getInt("password"));
list.add(emp);
}
}
return list;
}
/*
@Test
public void Tests() throws Exception {
List<employee> count = selectemp(0,3);
for (employee item:count) {
System.out.println(item.getName());
}
}
*/
public int getCount() throws SQLException {
int result=0;
String sql="select count(*) as num from employee";
ResultSet rs= null;
try {
rs = executeQuery(sql);
} catch (Exception e) {
e.printStackTrace();
}
if(rs!=null){
if(rs.next()){
result=rs.getInt("num");
}
closeAll();
}
return result;
}
}
idea 中的接口package cn.bdqn.dao;import cn.bdqn.entity.employee;import java.sql.SQLException;import java.util.List;/** * Created by linlin on 2017/6/16. */public interface empdao { public L