private static final String findAll="select * from project";
private static final String delete = "delete from project where id=?";
public void delete(Integer[] projects){
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = ConnectionUtils.openConnection();
conn.setAutoCommit(false);
stmt = conn.prepareStatement(delete);
for(int i=0;i<projects.length;i++){
stmt.setInt(1, projects[i]);
stmt.addBatch();
}
stmt.executeBatch();
conn.commit();
}catch(Exception e){
try {
conn.rollback();
} catch (SQLException e1) {
}
e.printStackTrace();
throw new RuntimeException(e);
}finally{
ConnectionUtils.closeConnection(conn);
}
}
public List<Project> findAll(){
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = ConnectionUtils.openConnection();
stmt = conn.prepareStatement(findAll);
rs = stmt.executeQuery();
List<Project> list = new ArrayList<Project>();
while(rs.next()){
Project project = new Project();
project.setId(rs.getInt(1));
project.setNo(rs.getString(2));
project.setName(rs.getString(3));
project.setStartDate(rs.getDate(4));
project.setEndDate(rs.getDate(5));
list.add(project);
}
return list;
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException(e);
}finally{
ConnectionUtils.closeConnection(conn);
}
}