CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  J2SE / 基础类

JAVABEAN的疑问请大家看看!1!!!!!!

楼主freedom1980(力促)2004-09-03 17:49:54 在 Java / J2SE / 基础类 提问

第一个代码;  
  主要是执行SQL语句取数据。  
  public   class   Lookup   {  
   
  public   Lookup(){}  
  public   ArrayList   gethash()   throws   SQLException{  
        ResultSet   st   =   null;  
  Hashtable   hs=new   Hashtable();  
  ArrayList   al=new   ArrayList();  
  String   goodsname[]=new   String[20];  
  String   unit[]=new   String[10];  
  String   introduction[]=new   String[10];  
  String   company[]=new   String[10];  
  String   price[]=new   String[20];  
  String   total[]=new   String[10];  
   
  ConnectSql   cql=new   ConnectSql();  
  try{  
   
  String   sql="select   goodsname,introduction,unit,company,price,total   from   goods   ";  
  st=cql.executeQuery(sql);  
  while(st.next()){  
  al.add(st.getString("goodsname"));  
  al.add(st.getString("unit"));  
  al.add(st.getString("introduction"));  
  al.add(st.getString("company"));  
  al.add(st.getString("price"));  
  al.add(st.getString("total"));  
   
              }  
                 
  }   catch(SQLException   e){  
  System.out.println("the   sql   error:"+e.getMessage());  
                    }   catch   (Exception   e)   {  
   
  e.printStackTrace();  
  }    
   
              return   al;  
                }  
  }  
  这种是向页面返回结果集再   显示  
  根本没用到我的BEAN   啊  
  package   Bean;  
   
  /**  
    *   @author   ms  
    *  
    *   To   change   the   template   for   this   generated   type   comment   go   to  
    *   Window>Preferences>Java>Code   Generation>Code   and   Comments  
    */  
  public     class   GoodsBean{  
   
  String   goodsname;  
  String   introduction;  
  String   unit;  
  String   company;  
  float     price;  
  int   total;  
  public     void   setGoodsname(String   goodsname){  
    this.goodsname=goodsname;  
    }  
    public   String   getGoodsname(){  
    return   (this.goodsname);  
    }  
  public   void   setIntroduction(String   introduction){  
    this.introduction=introduction;  
    }  
    public   String   getIntroduction(){  
    return   (this.introduction);  
    }  
    public     void   setUnit(String   unit){  
    this.unit=unit;  
    }  
    public   String   getUnit(){  
    return   (this.unit);  
    }  
    public     void   setCompany(String   company){  
    this.company=company;  
    }  
    public   String   getCompany(){  
    return   (this.company);  
    }  
  public   void   setPrice(float   price){  
    this.price=price;  
    }  
    public   float   getPrice(){  
    return   (this.price);  
    }  
  public   void   setTotal(int   total){  
    this.total=total;  
    }  
    public   int   getTotal(){  
    return   (this.total);  
    }  
    }  
   
  请问我在执行SQL语句后该怎么做   是直接向BEAN里添加结果吗?  
  但是也是添加结果集啊  
  而且页面的SCOPE该设成什么才能直接调用JAVABEAN的GETXXX方法  
  请高手多多指点  
   
  问题点数:0、回复次数:7Top

1 楼panzhiwei(panzhiwei008)回复于 2004-09-03 17:57:49 得分 0

支持!Top

2 楼ybsoft(☆☆☆☆☆)回复于 2004-09-03 17:58:45 得分 0

SCOPE   =   REQUESTTop

3 楼freedom1980(力促)回复于 2004-09-03 18:25:10 得分 0

try{  
   
  String   sql="select   goodsname,introduction,unit,company,price,total   from   goods   ";  
  st=cql.executeQuery(sql);  
  while(st.next()){  
  gb.setGoodsname(st.getString("goodsname"));  
  gb.setGoodsname(st.getString("unit"));  
  gb.setGoodsname(st.getString("introduction"));  
  gb.setGoodsname(st.getString("company"));  
  gb.setGoodsname(st.getString("price"));  
  gb.setGoodsname(st.getString("total"));  
            al.add(gb);  
              }  
                 
  }   catch(SQLException   e){  
  System.out.println("the   sql   error:"+e.getMessage());  
                    }   catch   (Exception   e)   {  
   
  e.printStackTrace();  
  }    
                     
              return   al;  
                }  
  }  
  页面SCOPE我用的是REQUEST啊    
  <%     int   i=0;  
            int   a;  
            int   j=0;  
            ArrayList   al=new   ArrayList();  
            al=lookup.gethash();  
            Object   ia[]=al.toArray();  
            a=ia.length;  
   
      %>  
  function   lookup(){  
  var   index=<%=a%>;  
  var   n=0;  
  document.write("<table   width=500   height=500   border=1   align=center><tr>");  
  document.write("<th>商品名称</th><th>价格</th><th>计量单位</th><th>库存</th><th>产品介绍</th><th>生产厂家</th><tr>");  
  for(n=0;n<index;n++)  
  {  
  document.write("<td><%=gb.getGoodsname()%></td><td   colspan=1><%=gb.getPrice()%></td><td><%=gb.getUnit()%></td><td><%=gb.getTotal()%></td><td   colspan=1><%=gb.getIntroduction()%></td><td><%=gb.getCompany()%></td></table>");  
  }  
  return   true;  
  }  
  但是显示的结果要摸是0要么是NULLTop

4 楼zheng2361yyyyyy(风云)回复于 2004-09-03 18:29:17 得分 0

你说的我看的不太明白,但是  
  java   Bean   同时也是一个JAVA类     你可以像调用其它类一样调用呀  
  <%  
        ResultSet   set=Bean.getResultSet();  
  %>Top

5 楼gameboy999(-'_'-)回复于 2004-09-03 18:31:58 得分 0

你从数据库中取数据怎么这么怪啊?Top

6 楼zhlmmc(zhlmmc)回复于 2004-09-03 18:37:36 得分 0

说实话,眼花Top

7 楼freedom1980(力促)回复于 2004-09-03 19:02:23 得分 0

<%  
        ResultSet   set=Bean.getResultSet();  
  %>  
   
  你的意思是我的JAVA程序不用从后台返回结果集  
  直接用上面的语句就可以从BEAN里获取数据了  
  但是D:\tomcat4.1\work\Standalone\localhost\examples\lookgoods_jsp.java:79:   cannot   resolve   symbol  
  symbol     :   method   getResultSet   ()  
  location:   class   Bean.GoodsBean  
            ResultSet   st=gb.getResultSet();  
                                           
  Top

相关问题

  • 请教:对sizeof的疑问
  • 疑问。 请大家帮忙!
  • creatElement疑问,请帮忙!
  • Wscript?病毒吗?疑问?请解答。
  • 菜鸟疑问,请众高手帮忙!!!!
  • 疑问,请PHP高手帮助
  • 疑问多多,请大家进来啊?
  • 日期控件DTPicker的疑问?请教~~~
  • 记录删除疑问,请您帮忙!
  • STL中的一些疑问,请赐教

关键词

  • 页面
  • sql
  • goodsname
  • setgoodsname
  • introduction
  • getstring
  • cql
  • unit
  • al
  • st

得分解答快速导航

  • 帖主:freedom1980

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo