使用 ResultSet rs = ps.executeQuery();
publicCategoryquerybyid(intid){Categorycate=null;try{ps=cn.prepareStatement("select*f...
public Category querybyid(int id){
Category cate=null;
try {
ps = cn.prepareStatement("select * from _category where id=?");
ps.setString(1,"id");
ResultSet rs = ps.executeQuery();
while(rs.next()){
cate=new Category();
cate.setId(rs.getInt(id));
cate.setName(rs.getString("name"));
cate.setDescription(rs.getString("description"));
}
} catch (Exception ex) {
ex.printStackTrace();
} 为什么while方法总是不执行 展开
Category cate=null;
try {
ps = cn.prepareStatement("select * from _category where id=?");
ps.setString(1,"id");
ResultSet rs = ps.executeQuery();
while(rs.next()){
cate=new Category();
cate.setId(rs.getInt(id));
cate.setName(rs.getString("name"));
cate.setDescription(rs.getString("description"));
}
} catch (Exception ex) {
ex.printStackTrace();
} 为什么while方法总是不执行 展开
1个回答
2013-07-18
展开全部
用下面的代码测试一下咯:public Category querybyid(int id){
Category cate=null;
try {
ps = cn.prepareStatement("select * from _category where id=?");
ps.setString(1,"id");
ResultSet rs = ps.executeQuery(); System.out.println("是否有数据:" + rs.newxt()); while(rs.next()){
cate=new Category();
cate.setId(rs.getInt(id));
cate.setName(rs.getString("name"));
cate.setDescription(rs.getString("description"));
}
} catch (Exception ex) {
ex.printStackTrace();
}
Category cate=null;
try {
ps = cn.prepareStatement("select * from _category where id=?");
ps.setString(1,"id");
ResultSet rs = ps.executeQuery(); System.out.println("是否有数据:" + rs.newxt()); while(rs.next()){
cate=new Category();
cate.setId(rs.getInt(id));
cate.setName(rs.getString("name"));
cate.setDescription(rs.getString("description"));
}
} catch (Exception ex) {
ex.printStackTrace();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询