1, DTO is not a design pattern. Accurately say, it just a technology.
DTO stand for Data Transfer Object.
2, you need to use transfer data from database to other places not use ResultSet
, DTO may be a better choice.
3,DTO general application in the software development of multi-layer architecture,eg MVC.
Ex:
class User{
private String id;
private String age;
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
class DateAccess{
public User getUserInfo(String id){
User user= new User();
String sql ="select id,name ,age from user where id =?";
ResultSet rs = query(sql,id);
while(rs!=null&&rs.next()){
user.setId(rs.getString("id"));
user.setName(rs.getString("name"));
user.setAge(rs.getString("age"));
}
return user;
}
}