日期:2014-05-19  浏览次数:20657 次

各位高手,我这三个方法为什么输出后,有的为0呢?其实代码一点都不多,我写的挺规整的……主要看几行代码就行了
在jsp里面的相关代码如下:
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String stype=request.getParameter("booktype");
int booktype=Integer.parseInt(stype);
int pagenow=1;
int pagesize=6;
GoodsBeanBo gbb=new GoodsBeanBo();
int rowcount=gbb.getrowCount(booktype);
ArrayList al=gbb.getBook(booktype,pagenow);
int pagecount=gbb.getpageCount(rowcount,pagesize);
int size=al.size();
%>

<body>
  <%= rowcount%>
  <%= pagecount%>
  <%=size %>
  </body>

可是为什么输出的size为0呢?
后台说错误在public ArrayList getBook方法的这一行:st=ct.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
可是这一行能有什么错误呢?请指点!!谢谢 高分!



java的相关代码如下:各位大侠,帮忙看看,代码很规整没大家想想的那么麻烦……
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.createStatement(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);
}else{
rowcount=0;
}
}catch (Exception e){
e.printStackTrace();
}finally{
this.close();
}
return rowcount;
}
//得到总页数pagecount
public int getpageCount(int rowcount,int pagesize ){

int pagecount=0;
try {
if(rowcount%pagesize==0){
pagecount=rowcount/pagesize;
}else{
pagecount=(rowcount/pagesize)+1;
}


}catch (Exception e){
e.printStackTrace();
}finally{
this.close();
}
return pagecount;
}
//得到某页的信息
public ArrayList getBook(int booktype,int pagenow){
ArrayList al=new ArrayList();
try {
st=ct.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs=st.executeQuery("select * from goods where goodstype="+booktype+" LIMIT "+(pagenow-1)*6+","+6);
while(rs.next()){
GoodsBean gb=new GoodsBean();
gb.setGoodsid(rs.getInt("goodsid"));
gb.setGoodsname(rs.getString("goodsname"));
gb.setGoodsinfo(rs.getString("goodsinfo"));
gb.setGoodsprice(rs.getString("goodsprice"));
gb.setGoodsnum(rs.getInt("goodsnum"));
gb.setPublisher(rs.getString("publisher"));
gb.setGoodstype(rs.getInt("goodstype"));
gb.setGoodsphoto(rs.getString("goodsphoto"));
gb.setGoodsauthor(rs.getString("goodsauthor"));
al.add(gb);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
this.close();
}
return al;
}

------解决方案--------------------
应该是Connection ct 连接对象的问题 

如果先执行这个没问题
int rowcount=gbb.getrowCount(booktype);

然后 有代码 
finally{
this.close();
}
是关闭ct连接的意思吗?

再到
ArrayList al=gbb.getBook(booktype,pagenow);
的时候 

ct为空或已关闭
createStatement自然会报错

以上都是猜测

没看到楼主 的this.close();怎么定义的

楼主 最好把异常的错误发上来
------解决方案--------------------
探讨

this.close();是关闭rs,st,ct.
异常我都发啦,就是那句的问题,
求教 怎么在打开一个JSP页面后全屏,并且屏蔽crtl+tab切换其他窗口