为什么会出现异常 java.lang.NullPointerException

fire_wang 2009-06-07 01:59:14
public List<BbsRootieInfo> getAllRoot() {

ArrayList rootList = new ArrayList<BbsRootieInfo>();
Connection conn = null;
try {
conn = DBUtils.getConnection();
String sql = "select * from dbo.tb_bbs";
Statement st = conn.createStatement();

ResultSet rs = st.executeQuery(sql);
System.out.println(rs.getRow());
while (rs.next()) {
BbsRootieInfo root = new BbsRootieInfo();

root.setBbs_id(rs.getInt(1));
root.setBbs_boardID(rs.getInt(2));
root.setBbs_title(rs.getString(3));
root.setBbs_content(rs.getString(4));
root.setBbs_sender(rs.getString(5));
root.setBbs_sendTime(rs.getString(6));
root.setBbs_face(rs.getString(7));
root.setBbs_opTime(rs.getString(8));
root.setBbs_isTop(rs.getString(9));
root.setBbs_toTopTime(rs.getString(10));
root.setBbs_isGood(rs.getString(11));
root.setBbs_toGoodTime(rs.getString(12));

rootList.add(root);

}
rs.close();
st.close();

} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return rootList;
}







...全文
178 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
空指针异常是程序里面某个对象为空
fire_wang 2009-06-08
  • 打赏
  • 举报
回复
谢谢 各位
解决了

是因为数据库中没有数据 又没处理没有数据的情况
Study_Work_2009 2009-06-07
  • 打赏
  • 举报
回复
贴代码看看
秋9 2009-06-07
  • 打赏
  • 举报
回复
是那一行抛的java.lang.NullPointerException
njclsc 2009-06-07
  • 打赏
  • 举报
回复
把表前面的dbo去掉
sun_cat 2009-06-07
  • 打赏
  • 举报
回复
希望你能把异常代码贴出来,感觉不是你说的查不出来数据。
即使是查不出来数据也不应该有java.lang.NullPointerException
布丁88 2009-06-07
  • 打赏
  • 举报
回复
重新建一个工作区就可以了
fire_wang 2009-06-07
  • 打赏
  • 举报
回复
在数据库中执行有结果集

为什么呢?
谢谢回复
fire_wang 2009-06-07
  • 打赏
  • 举报
回复
为什么 String sql = "select * from dbo.tb_bbs";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
执行后结果集中没有数据呢?

在数据库中执行select * from dbo.tb_bbs
bbs_id bbs_boardID bbs_title bbs_content bbs_sender bbs_sendTime bbs_face bbs_opTime bbs_isTop bbs_toTopTime bbs_isGood bbs_toGoodTime
1 1 JSP程序开发中有那些设计模式? 请问各位,在JSP开发中有哪些开发模式? tsoft 2008-01-02 10:31:10.000 face3.gif 2008-01-02 10:31:10.000 0 2008-01-07 11:36:09.000 1 1900-01-01 00:00:00.000
2 1 乱码问题!! 请问,在JSP中如何解决获取表单数据后的中文乱码问题??谢谢!! tsoft 2008-01-01 08:33:52.000 face11.gif 2008-01-02 10:46:05.000 0 2008-01-07 13:26:29.000 1 1900-01-01 00:00:00.000
3 1 开发JSP程序通常使用哪些框架? 请问,开发JSP程序比较常用和流行的开发框架有哪些?? 许久 2008-01-02 08:37:15.000 face3.gif 2008-01-07 13:59:26.000 1 2008-01-07 13:59:32.000 1 1900-01-01 00:00:00.000
10 2 fdsfdsfd fdsfdsfdsfdfdfdfdfd 00 2008-01-07 11:49:02.000 face0.gif 2008-01-07 11:49:13.000 0 1900-01-01 00:00:00.000 0 1900-01-01 00:00:00.000
13 19 随时回答你的问题 如果你有什么问题或者疑问可随时发帖子给我,我会及时给您回复. 00 2008-01-07 14:16:49.000 face0.gif 2008-01-07 14:17:06.000 0 1900-01-01 00:00:00.000 0 1900-01-01 00:00:00.000
14 1 随时回答你的问题 如果你有什么问题可随时发布帖了,我会及时的回复您. tsoft 2008-01-07 14:33:14.000 face0.gif 2008-01-07 14:33:14.000 0 1900-01-01 00:00:00.000 0 1900-01-01 00:00:00.000

58,452

社区成员

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

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