📄 ex8_5.txt
字号:
Example 8.5 CustomerDAO.java: Transfer Object Collection Strategy
package com.corej2eepatterns.dao;
// imports
public class CustomerDAO {
. . .
// Create a list of Transfer Objects and return it
public List findCustomers(CustomerTO criteria)
throws DAOException {
Connection con = getConnection();
ResultSet rs = null;
ArrayList custList = new ArrayList();
String searchSQLString = getSearchSQLString(criteria);
try {
con = getConnection();
java.sql.Statement stmt =
con.createStatement(. . . );.
rs = stmt.executeQuery(searchSQLString);
while(rs.next()) {
//create the transfer object using data from rs
cust = new CustomerTO();
cust.setId(rs.getString(1));
cust.setName(rs.getString(2));
. . .
// add the TO to the list
custList.add(cust);
}
} catch (Exception e) {
// handle exception
} finally {
// close connections
}
return custList;
}
. . .
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -