public class TestDao {
public void add(TestDTO dto) throws ClassNotFoundException, SQLException{
Class.forName("com.mysql.jdbc.Driver");
Connection conn= DriverManager.getConnection("jdbc:mysql://localhost/springbook", "spring", "book");
PreparedStatement pstmt = conn.prepareStatement("insert into users(id,name,password) value(?,?,?)");
pstmt.setString(1, dto.getId());
pstmt.setInt(2, dto.getName());
pstmt.setString(3, dto.getPwd());
pstmt.executeUpdate();
pstmt.close();
conn.close();
}
}
public class TestDTO {
private String id;
private String name;
private String pwd;
public String getId() {
return id;
}
public void setId(String id) {
this.name = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.name = pwd;
}
}
VO는 특정한 비즈니스 값을 담는 객체이고, DTO는 Layer간의 통신 용도로 오고가는 객체