怎么检测DAO层中的方法

抓哇菜鸟 2014-02-05 11:23:29
如何检测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;
}
}
...全文
550 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jack_Jia007 2014-02-09
  • 打赏
  • 举报
回复
直接debug模式断点调试
qiuqiupeng 2014-02-07
  • 打赏
  • 举报
回复
用junit写个桩模块来测试
星河千幻 2014-02-07
  • 打赏
  • 举报
回复
用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);
		}
	 }
 }
翘班党 2014-02-07
  • 打赏
  • 举报
回复
list.isEmpty() 为空
齐岳 2014-02-07
  • 打赏
  • 举报
回复
jdbc的话,自己写个main方法调取要测的方法测一下, 你上面的这个方法可以在main方法直接输出 xxx.findAllNotice().size(),不为0就是存在数据
抓哇菜鸟 2014-02-05
  • 打赏
  • 举报
回复
我想是另外写一个类,然后判断它是否从数据库取到了数据,但是我卡在如何把list中所有的内容列出来、不会..
TuskueNeko 2014-02-05
  • 打赏
  • 举报
回复
rs如果是空 while里的代码是不会执行的 这样还不好判断?
javabugsmaker 2014-02-05
  • 打赏
  • 举报
回复
这个可以直接运行看效果吧,设个断点看看能不能查出数据就行了。或者是把sql语句打印出来也行。
teemai 2014-02-05
  • 打赏
  • 举报
回复
list.size() > 0

81,114

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧