/** 装载制定类的所有持久化对象*/
public List listAll(String clazz, String[] colmunNames){
// select empId,empName from employee
String sql = "select ";
for (String colmun : colmunNames) {
sql += colmun+',';
}
// 去除最后一个列名后的逗号
sql = sql.substring(0, sql.length()-1)+" from "+clazz;
List list = new ArrayList();
//连接数据库的3个对象
Connection conn = null;
ResultSet rst = null;
PreparedStatement pst = null;
try {
//获取连接
conn = DaoFactory.getConn();
pst = conn.prepareStatement(sql);
//执行SQL
rst = pst.executeQuery();
while(rst.next()) {
String str = new String();
//循环读取列对象
for (String string : colmunNames) {
str+=rst.getString(string)+":";
}
list.add(str);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DaoFactory.closeAll(conn, pst, rst);
}
return list;
}