我就是不知道 查询的记录是否为第一条记录阿,因为是根据外界传递过来的参数为条件查询的 String sqlCommand = new String(); ConnClub bridge = new ConnClub(); Connection con = bridge.getConnection(); ResultSet rs; sqlCommand = "Select * From GVclubUsers "; sqlCommand += " where userName = ?" ; PreparedStatement pps = con.prepareStatement(sqlCommand); pps.setString(1, uName); rs = pps.executeQuery(); if(rs.next()){…………………………………………如果uName是最后一条记录 rs.next() 总是为flase
用while(rs.next()) if只能查询一条记录
得到最后一条记录可以在后面加order by xxx sqlCommand = "Select * From GVclubUsers "; sqlCommand += " where userName = ?" ; sqlCommand += " order by ID desc" 如果ID是,1,2,3,4,5,6 那么查询出来的排序会变成6,5,4,3,2,1 然后用if(rs.next())就是最后一条记录了。
没有看见楼主的倒叙排序的语句啊??用rs.last()直接定为多好,为什么要这么麻烦呢
sqlCommand = "Select * From GVclubUsers "; sqlCommand += " where userName = ?" 肯定在的 userName是唯一的没有重复,当条件指定的是最后一条记录时返回false也就是说他也可能不是最后一条记录,我只是想判断 userName等于某值是 他是否存在在数据库里,不知道该怎么做!?rs.last()是不是只能在数据为最后一条时才返回true如果不是最后一条数据呢?
ConnClub bridge = new ConnClub();
Connection con = bridge.getConnection();
ResultSet rs;
sqlCommand = "Select * From GVclubUsers ";
sqlCommand += " where userName = ?" ;
PreparedStatement pps = con.prepareStatement(sqlCommand);
pps.setString(1, uName);
rs = pps.executeQuery();
if(rs.next()){…………………………………………如果uName是最后一条记录 rs.next() 总是为flase
if只能查询一条记录
sqlCommand = "Select * From GVclubUsers ";
sqlCommand += " where userName = ?" ;
sqlCommand += " order by ID desc"
如果ID是,1,2,3,4,5,6
那么查询出来的排序会变成6,5,4,3,2,1
然后用if(rs.next())就是最后一条记录了。
sqlCommand += " where userName = ?" 肯定在的 userName是唯一的没有重复,当条件指定的是最后一条记录时返回false也就是说他也可能不是最后一条记录,我只是想判断 userName等于某值是 他是否存在在数据库里,不知道该怎么做!?rs.last()是不是只能在数据为最后一条时才返回true如果不是最后一条数据呢?
想查询某一条记录是否存在在数据库if(rs.next())来判断 如果查询符合条件的记录存在 在数据库的最后一条 怎么总是返回flase???
select count(*) from table where ...
然后判断rs.getInt(1)是否大于0,这个就是满足你查询条件的记录数