为何从数据库中查询出来的ResultSet.next是fasle,大家帮我看看

chenwali 2008-07-29 07:32:03
public class TopicDao {
private DataSource ds ;
private Connection conn ;
public TopicDao()
{
try{
Context ctx = new InitialContext();
ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/MyOracle");
}catch(Exception e){
e.printStackTrace();
}
}
public List<Topic> findAllByForumID(int id)throws SQLException
{
String chen = "select * from TOPIC where BANKUAIID='"+id+"' and FUTIEZIID=0";
List<Topic> list = new ArrayList<Topic>();
try{
System.out.println(list);
conn = ds.getConnection() ;//连接没有问题
System.out.println(conn);
java.sql.PreparedStatement gan = conn.prepareStatement(chen);
gan.setInt(1, id);
java.sql.ResultSet rs = gan.executeQuery();
System.out.println(id);
System.out.println(rs.next());//这里输出false;
System.out.println(id);//这里输出 ID
//以上都没有问题,可是当走要进入while循环时,就跳到 finally 里面去了
while(rs.next())
{
System.out.println("sdfs");
Topic bean = new Topic();
bean.setId(rs.getInt(1));
bean.setName(rs.getString(2));
bean.setContent(rs.getString(3));
bean.setPost_user_id(rs.getInt(4));
bean.setTime(rs.getTimestamp(5));
bean.setForum_id(rs.getInt(6));
bean.setSuper_id(rs.getInt(7));
list.add(bean);
}
}catch(SQLException e){
e.printStackTrace();
}
finally
{
conn.close();
}
return list;
}

很急。在线等!!!
...全文
111 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
流年岁月 2009-01-13
  • 打赏
  • 举报
回复
学习了,那个查询出来的结果是不是空的?

6,909

社区成员

发帖
与我相关
我的任务
社区描述
《新程序员》读者俱乐部
其他 其他
社区管理员
  • 《程序员》杂志社区
  • SoftwareTeacher
  • 《新程序员》编辑部
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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