为何从数据库中查询出来的ResultSet.next是fasle,大家帮我看看
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;
}
很急。在线等!!!