1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| public class MemberDAO { Connection con =null; PreparedStatement pstmt = null; ResultSet rs = null; String sql = ""; public Connection getCon() throws Exception{ Context init= new InitialContext(); DataSource ds = (DataSource) init.lookup("java:comp/env/jdbc/model2DB"); con = ds.getConnection(); return con; } public void closeDB(){ try{ if(rs != null) rs.close(); if(pstmt != null) pstmt.close(); if(con != null) con.close(); } catch (SQLException e) { e.printStackTrace(); } } public void insertMember(MemberBean mb){ try { con = getCon(); sql = "insert into itwill_member value(?,?,?,?,?,?,?)"; pstmt = con.prepareStatement(sql); pstmt.setString(1, mb.getId()); pstmt.setString(2, mb.getPw()); pstmt.setString(3, mb.getName()); pstmt.setInt(4, mb.getAge()); pstmt.setString(5, mb.getGender()); pstmt.setString(6, mb.getEmail()); pstmt.setTimestamp(7, mb.getReg_date()); pstmt.executeUpdate(); System.out.println("회원가입성공"); } catch (SQLException e) { System.out.println("sql구문땜시 회원가입실패"); e.printStackTrace(); } catch (Exception e) { System.out.println("회원가입실패"); e.printStackTrace(); } finally { closeDB(); } } }
|