public void addUser(User user) throws DbFailException { Connection connection = null; PreparedStatement statement = null; String insertQuery = "INSERT INTO users(user_name, user_password, user_email, user_status) VALUES(?, ?, ?, ?)"; try { connection = datasource.getConnection(); connection.setAutoCommit(false); statement = connection.prepareStatement(insertQuery); statement.setString(1, user.getUserName()); statement.setString(2, user.getUserPassword()); statement.setString(3, user.getUserEmail()); statement.setString(4, user.getUserStatus()); statement.executeUpdate(); connection.commit(); } catch (SQLException e) { e.printStackTrace(); } finally { datasource.closePreparedStatement(statement); datasource.closeConnection(connection); } }