联合查询
demp表格+dept表格
等值连接
外连接
内连接
Emp deptno(聚合关系)emp ——> dept 一对多关系
public class DaoEmp {
//数据持久层
private String className = "com.mysql.jdbc.Driver" ; //"com.mysql.jdbc.Driver"
private String url = "jdbc:mysql://localhost:3306/test?characterEncoding=utf-8&verifyServerCertificate=false&useSSL=true" ;
private String user = "root" ;
private String password = "root" ;
public ArrayList<Emp> limit(int rowIndex){
Connection con = null ;
PreparedStatement pstat = null ;
ResultSet rs = null ;
ArrayList<Emp> list = new ArrayList<Emp>();
try {
Class.forName(className);
con = DriverManager.getConnection(url,user,password);
String sql = "SELECT * FROM EMP,DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO LIMIT ?,5";
pstat = con.prepareStatement(sql);
pstat.setInt(1,rowIndex);
rs = pstat.executeQuery();
while(rs.next()){
Emp emp = new Emp();
emp.setEmpno(rs.getInt("empon"));
emp.setEname(rs.getString("ename"));
emp.setJob(rs.getString("job"));
emp.setMgr(rs.getInt("mgr"));
emp.setHireDate(rs.getDate("hiredate"));
emp.setSal(rs.getInt("sal"));
emp.setComm(rs.getInt("comm"));
Dept dept = new Dept();
dept.setDeptno(rs.getInt("deptno"));
dept.setDname(rs.getString("dname"));
dept.setLoc(rs.getString("loc"));
emp.setDeptno(dept);
list.add(emp);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
if (rs!=