@Override public Object invoke(MethodInvocation invocation) throws Throwable { Method method = invocation.getMethod(); Transactional annotation = method.getAnnotation(Transactional.class); if (annotation == null || context.getConnection() != null) { return invocation.proceed(); } Connection connection = context.getConnection(true); connection.setAutoCommit(false); try { Object rv = invocation.proceed(); connection.commit(); return rv; } catch (Exception e) { connection.rollback(); throw e; } finally { connection.close(); context.removeConnection(); } }
public Member getMemberInfo(String id) { Member member = null; try { Connection conn = ConnectionContext.getConnection(); String sql = "SELECT * FROM member WHERE id=?"; PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, id); // 메소드 파라미터 id를 sql 첫 번째 ?에 세팅 ResultSet rs = pstmt.executeQuery(); if (rs.next()) { member = new Member(); member.setId(rs.getString("id")); member.setPw(rs.getString("password")); member.setEmail(rs.getString("email")); member.setPhone(rs.getString("phone")); member.setRegDate(rs.getDate("reg_date")); } rs.close(); pstmt.close(); conn.close(); } catch (Exception e) { e.printStackTrace(); } return member; }