日期:2014-05-17  浏览次数:20710 次

怎么检测DAO层中的方法
如何检测DAO层中的方法里的数据是否取到
public List findAllNotice(){
Notice notice = null;
List<Notice> list = new ArrayList<Notice>();

try {
Connection conn = getConnection();
String sql = "select nid,ntitle " +
"from notice " +
"where nendtime>=to_date(to_char(sysdate,'yyyy/mm/dd'),'yyyy/mm/dd')";
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while(rs.next()){
notice = new Notice();
notice.setNid(rs.getInt(1));
notice.setNtitle(rs.getString(2));
notice.setNcontent(rs.getString(3));
notice.setNstarttime(rs.getDate(4));
notice.setNendtime(rs.getDate(5));
list.add(notice);
}
closeAll(conn, ps, rs);
return list;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
------解决方案--------------------
用JUnit测试或者写个main方法,循环List,把里面的每个Notice对象都打印出来不就行了
public class Test{
public static void main(String[] args) {
List<Notice> list = Xxxx.findAllNotice();//Xxxx是你那个类名

for(Notice notice : list) {
int id = notice.getNid();
String title = notice.getNtitle();
String content = notice.getNcontent();
Date starttime = notice.getNstarttime();
Date endtime = notice.getNendtime();
System.out.println("id: " + id + "title: " + title + "content: " + content + "starttime: " + starttime + "endtime: " + endtime);
}
 }
 }