MemberService.java (Interface)
MemberServiceImpl.java (Class)
다른파일에서 파일이 삭제되어 생기는 오류 해결하기
MemberDao.java (Interface)
MemberDaoImpl.java (Class)
package dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import conn.DBConn;
import dto.MemberVo;
public class MemberDaoImpl implements MemberDao{
DBConn db = DBConn.getInstance();
Connection con = null;
String sql =null;
PreparedStatement pstmt = null;
MemberVo m = null;
ResultSet rs = null;
List<MemberVo> list = null;
@Override
public void insert(MemberVo m) {
try{ con = db.getConnect();
sql = " insert into member_tbl_02 ";
sql = sql + " (custno, custname, phone, address, joindate, grade, city ) " ;
sql = sql + " values(?,?,?,?,?,?,?) ";
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, m.getCustno());
pstmt.setString(2,m.getCustname());
pstmt.setString(3,m.getPhone());
pstmt.setString(4,m.getAddress());
pstmt.setString(5, m.getJoindateS());
pstmt.setString(6, m.getGrade());
pstmt.setString(7, m.getCity());
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally{
try {
if (pstmt != null){pstmt.close();}
if (con != null){con.close();}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
@Override
public void delete(MemberVo m) {
try {
con = db.getConnect();
sql = "delete from member_tbl_02 where custno=?";
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, m.getCustno());
pstmt.executeUpdate();
} catch( Exception e) {
e.printStackTrace();
}finally{
try {
if (pstmt != null){pstmt.close();}
if (con != null){con.close();}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
@Override
public void editOk(MemberVo m) {
try {
con = db.getConnect();
sql = " update member_tbl_02 set ";
sql = sql + " custname=?, phone=?, address=?, joindate=?, grade=?, city=? " ;
sql = sql + " where custno=? ";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, m.getCustname());
pstmt.setString(2, m.getPhone());
pstmt.setString(3, m.getAddress());
pstmt.setString(4, m.getJoindateS());
pstmt.setString(5, m.getGrade());
pstmt.setString(6, m.getCity());
pstmt.setInt(7, m.getCustno());
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
if (rs != null ) {rs.close();}
if (pstmt != null){pstmt.close();}
if (con != null){con.close();}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
@Override
public MemberVo edit(int k) {
try {
con = db.getConnect();
sql = "select * from member_tbl_02 where custno=?";
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, k);
rs = pstmt.executeQuery();
rs.next();
m = new MemberVo();
m.setCustno(rs.getInt("custno"));
m.setCustname(rs.getString("custname"));
m.setPhone(rs.getString("phone"));
m.setAddress(rs.getString("address"));
m.setJoindateS(rs.getString("joindate"));
m.setGrade(rs.getString("grade"));
m.setCity(rs.getString("city"));
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
if (rs != null ) {rs.close();}
if (pstmt != null){pstmt.close();}
if (con != null){con.close();}
} catch (SQLException e) {
e.printStackTrace();
}
}
return m;
}
@Override
public List<MemberVo> selectAll(MemberVo m) {
list = new ArrayList<MemberVo>();
String ch1 = m.getCh1();
String ch2 = m.getCh2();
try {
con = db.getConnect();
if(m.getCh1() == null || m.getCh2() == "") {
sql = "select * from member_tbl_02";
}else {
if(ch1.equals("custname")) {
sql = "select * from member_tbl_02 where custname like '%"+ch2+"%' ";
}else {
sql = "select * from member_tbl_02 where address like '%"+ch2+"%' ";
}
}
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()) {
m = new MemberVo();
m.setCustno(rs.getInt("custno"));
m.setCustname(rs.getString("custname"));
m.setPhone(rs.getString("phone"));
m.setAddress(rs.getString("address"));
m.setJoindateS(rs.getString("joindate"));
m.setGrade(rs.getString("grade"));
m.setCity(rs.getString("city"));
list.add(m);
System.out.println();
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
if (rs != null ) {rs.close();}
if (pstmt != null){pstmt.close();}
if (con != null){con.close();}
} catch (SQLException e) {
e.printStackTrace();
}
}
return list;
}
}
[insert메서드 Controller]
[select 메서드 Controller]
<a href="/MVC2/MemberController?flag=r">회원목록 조회/수정</a>
[edit 메서드 Controller]
[editOk 메서드 Controller]
[delete 메서드 Controller]
<td><a href=/MVC2/MemberController?flag=d&custno=${m.custno}>${m.city}</a></td>