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

rs.next为0
Java code

public List<Record> querryByID(int id) throws Exception
    {
        list = new ArrayList<Record>();
        try
        {
            sql = "SELECT  carno,owner,dname,reason,date FROM record,depart WHERE  depart.did=record.depart AND rid=?";
            this.ps = this.connection.prepareStatement(sql);
            this.ps.setInt(1, id);
            ResultSet rs=this.ps.executeQuery();
            while (rs.next())
            {
                System.out.println("*********"+rs.next());
                record = new Record();
                record.setCno(rs.getString(1));
                record.setOwner(rs.getString(2));
                record.setDepartName(rs.getString(3));
                record.setReason(rs.getString(4));
                record.setDate(rs.getString(5));
                list.add(record);
            }
        } catch (Exception e)
        {
            throw e;
        } finally
        {
            if (this.ps != null)
            {
                try
                {
                    this.ps.close();
                } catch (Exception e)
                {
                    throw e;
                }
            }
        }
        return list;
    }
}




+++++++++++++0

这段代码运行到while(rs.next)时 为0,运行不下去了。

------解决方案--------------------
while (rs.next())
{
System.out.println("*********"+rs.next());


------解决方案--------------------
执行你那个sql语句,结果应该是只有一条数据吧?
去掉System.out.println("*********"+rs.next());试试。

------解决方案--------------------
System.out.println("*********"+rs.next());大哥你这里用.netx()了一下 如果你数据只有一条数据 它等于是next了2下 前面while里面有一下 这样他去读的是第二条数据,所以就为空。