我想从数据库中查找书的类型号为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;
}
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;
}
解决方案 »
- java对象怎么转成json数组 传到前台页面 求高手 解答
- 空的工程加入struts2的问过滤器之后访问报404
- 为何java多线程实现数据查询插入越来越慢?
- java SSH框架开发的一个笑话网站
- Interceptor has thrown exception, unwinding now(ClassCastException)
- 请问:JET怎么用呢?
- 想换程序学习的网友请进。
- [高分]请问各位,websphere中有无对class文件大小的限制,如果有的话,怎样取消这样的限制呢?
- 怎样在JDOM 9 beta版中通过XPath来修改XML节点的值?
- javaMail 问题,高手指点迷津
- he content of element type "set" must match (领分)
- 问一个捕获异常的问题
没有的话,去数据库那里执行
select count(*) from goods where goodstype=1
看看,输出是几。
执行之前
System.out.println("sql=="+sql);
输出来看看,如果还是0 的话,就是你的连接链的库不对,或是其他的问题了
也就是这一行:st=ct.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);我就纳闷了,这句能有什么错呢?