我的这个简单的算法错在哪呀?再简单不过的代码了 我真笨

xiaoshuidi123 2012-08-21 01:26:20
我想从数据库中查找书的类型号为1(即goodstype=1)的记录数,可结果为什么总是0呢???!!我写的代码如下:
public class GoodsBeanBo {


Connection ct=new ConnDb().getConn();
ResultSet rs=null;
Statement st=null;
public int getrowCount(int booktype){
int rowcount=0;
try {
st=ct.createStatemen(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=st.executeQuery("select count(*) from goods where goodstype="+booktype);
if(rs.next()){
rowcount=rs.getInt(1);
}

}catch (Exception e){
e.printStackTrace();
}finally{
this.close();
}
return rowcount;
}
...全文
108 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoshuidi123 2012-08-21
  • 打赏
  • 举报
回复
后台错误:at goods.wl.com.GoodsBeanBo.getrowCount(GoodsBeanBo.java:106)
也就是这一行:st=ct.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

我就纳闷了,这句能有什么错呢?
夜星云 2012-08-21
  • 打赏
  • 举报
回复
先定义一个变量String sql = "select count(*) from goods where goodstype="+booktype;
执行之前
System.out.println("sql=="+sql);
输出来看看,如果还是0 的话,就是你的连接链的库不对,或是其他的问题了
  • 打赏
  • 举报
回复
rowcount+=rs.getInt(1);
scbb 2012-08-21
  • 打赏
  • 举报
回复
看看控制台有出错信息吗?
没有的话,去数据库那里执行
select count(*) from goods where goodstype=1
看看,输出是几。
xiaoshuidi123 2012-08-21
  • 打赏
  • 举报
回复
对呀 我执行getrowCount(1)结果是0呀?郁闷
风尘中国 2012-08-21
  • 打赏
  • 举报
回复
你执行了getrowCount(1)得到的返回值是0么? 看看控制台有异常输出么

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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