Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void setTeamsForUser(User user, Team ... teams) {
- Connection con = null;
- PreparedStatement prepared = null;
- try {
- con = DriverManager.getConnection(URL);
- con.setAutoCommit(false);
- con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
- prepared = con.prepareStatement(SQL_INSERT_PAIR);
- prepared.setInt(1, user.getId());
- for (Team team : teams) {
- prepared.setInt(2, team.getId());
- prepared.executeUpdate();
- }
- con.commit();
- } catch (SQLException ex) {
- rollback(con);
- ex.printStackTrace();
- } finally {
- close(prepared);
- close(con);
- }
- }
- public void deleteTeam(Team team) {
- Connection con = null;
- PreparedStatement prepar = null;
- try {
- con = DriverManager.getConnection(URL);
- prepar = con.prepareStatement(SQL_DELETE_TEAM_BY_NAME);
- prepar.setString(1, team.getName());
- prepar.executeUpdate();
- } catch (SQLException ex) {
- ex.printStackTrace();
- } finally {
- close(prepar);
- close(con);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement