sql语句:sql语句中的in查询,是否包含
select * from sub_staff where idcard in (select idcard from staff);
方法其实简单,关键是写对sql语句
public static ArrayList showAll(){
Connection conn = null;
PreparedStatement pt = null;
ResultSet rs = null;
ArrayList<staffBean> staffs = new ArrayList<staffBean>();
try {
jdbcDtiver jdbcDriver=new jdbcDtiver();
conn = jdbcDriver.Driver();
String sql = "select * from sub_staff where idcard in (select idcard from staff)";
pt = conn.prepareStatement(sql);
rs = pt.executeQuery();
while (rs.next()) {
staffBean staff = new staffBean();
staff.setId(rs.getInt("id"));
staff.setName(rs.getString("name"));
staff.setIdcard(rs.getString("idcard"));
staffs.add(staff);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return staffs;
}
希望对大家有所帮助!