有!!
这个是封装结果的BEAN:
package com.tt.genwesite.ui;/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2003
 * Company:
 * @author
 * @version 1.0
 */public class TmagazineMidUpDetail {  public TmagazineMidUpDetail() {
dbClass="";
type ="";
EnglishTitle="";
ChineseTitle="";
lessondate  ="";
Id          =0;
textBody    ="";
audioPath   ="";
questionCount="";
picPath      ="";
note         ="";  }
public String dbClass;
public String type ;
public String EnglishTitle;
public String ChineseTitle;
public String lessondate  ;
public int Id          ;
public String textBody    ;
public String audioPath   ;
public String questionCount;
public String picPath      ;
public String note         ;}

解决方案 »

  1.   

    这是另外一个:
    package com.tt.genwesite.ui;/**
     * Title:
     * Description:
     * Copyright:    Copyright (c) 2003
     * Company:
     * @author
     * @version 1.0
     */public class TmagazineMidUpShow {  public TmagazineMidUpShow() {
    englishTitle         ="";
    chineseTitle         ="";
    lessonDate           ="";
    picPath              ="";
    audioPath            ="";
    lessonContent        ="";
    sytaxBBS             ="";
    listeningExer1       ="";
    listeningExer2       ="";
    sentence             ="";
    listeningExer1_Answer="";
    listeningExer2_Answer="";
    sentence_Answer      ="";
    translations         ="";
    vocabulary           ="";
    temp1                ="";
    temp2                ="";  }
    public String englishTitle         ;
    public String chineseTitle         ;
    public String lessonDate           ;
    public String picPath              ;
    public String audioPath            ;
    public String lessonContent        ;
    public String sytaxBBS             ;
    public String listeningExer1       ;
    public String listeningExer2       ;
    public String sentence             ;
    public String listeningExer1_Answer;
    public String listeningExer2_Answer;
    public String sentence_Answer      ;
    public String translations         ;
    public String vocabulary           ;
    public String temp1                ;
    public String temp2                ;}
      

  2.   

    在bean中定义一个方法,如下
    /*获取查询结果*/
        public ResultSet getResult()
        {
            ……
            return result;
        }
    至于去结果,就跟普通的rs.next(),无差别
      

  3.   

    这个是生成结果的BEAN
    package com.tt.genwesite.ui;import com.tt.genwesite.db.*;
    import com.tt.genwesite.util.*;
    import com.tt.genwesite.bean.SysConfValidator;
    import java.util.*;
    import java.lang.Integer;
    import java.sql.*;
    import org.apache.log4j.*;//开源的日志管理包
    /**
     * Title: TmagazineMidUp.java
     * Description:取出最新5期杂志的列表。
     * Copyright:    Copyright (c) 2002
     * Company:tidetime
     * @author:apollo
     * @version 1.0
     */public class TmagazineMidUp {  private static boolean weight = true;
      public TmagazineMidUp() {
      }    private static Category _log = GWTools._logger("tt.genwesite.ui");    public static void main(String[] args) {
          TmagazineMidUp man = new TmagazineMidUp();
    try
    {      man.queryTmagazineShow("2002-11");
          //System.out.println(show.englishTitle);      }
          catch(GWException e)
          {
          e.printStackTrace();
          }       }//查询表中本月记录
    //
        public TmagazineMidUpShow[] queryTmagazineShow ( String tSeltype,String tLessonDate) throws GWException
        {
          if(!SysConfValidator.verifyTime())
            {
                throw new GWException("系统已经失效。");
            }
            if(tLessonDate==null)
            {
                throw new GWException("方法调用错误:无效的参数。");
            }
            DatabaseConn db = new DatabaseConn();
            Connection conn = null;
            TmagazineMidUpShow magazineShow[];
            String sql="";
            String beginDate="";
            String endDate="";
           /*
            Calendar cal=Calendar.getInstance();
            int year=cal.get(Calendar.YEAR);
            int monthT=cal.get(Calendar.MONTH);
            int dateT=cal.get(Calendar.DATE);
            String month=monthT+"";
            if(monthT<10 && month.length()<2)
            {
            month="0"+month;
            }
            String date=dateT+"";
            if(dateT<10 && date.length()<2)
            {
            date="0"+date;
            }
            String today=year+"-"+month+"-"+date;
            */
           // int index=tLessonDate.indexOf("-");
            int sel_month=1;
            int sel_year=2000;
            if(tLessonDate.length()<8)
            {
             beginDate=tLessonDate+"-1";
             sel_month=Integer.parseInt(tLessonDate.substring(5,7));
             sel_year=Integer.parseInt(tLessonDate.substring(0,4));
            if(sel_month==1 ||sel_month==3||sel_month==5||sel_month==7||sel_month==8||sel_month==10||sel_month==12)
               endDate=tLessonDate+"-31";
             else if(sel_month==2)
                {
                 if(sel_year%4==0 &&sel_year%100!=0)
                  endDate=tLessonDate+"-29";
                  else
                   endDate=tLessonDate+"-28";
                 }
              else
               endDate=tLessonDate+"-30";
               sql = "select distinct  * FROM A_English where lessondate >= '"+beginDate+"' and lessondate <='"+endDate+"' order by lessondate asc";
            }
           else{
               //if(tSeltype==null || tSeltype.equals(""))
                // {
                  sql = "SELECT DISTINCT * FROM A_English WHERE lessonDate = '"+tLessonDate+"' ORDER BY lessonDate";
                  //System.out.print("tSeltype==null");
               //  }
               // else
               //   {  //System.out.print("tSeltype!=null");
                  /*
                  case "Translation" 'Translation
    sql_text="select distinct translations from A_English where lessondate='"&lessondate&"'"
    case "classRoom" 'classRoom
    sql_text="select distinct classroom from A_English where lessondate='"&lessondate&"'"
    case "Sentence_4u" 'Sentence_4u
    sql_text="select distinct sentence_4u from A_English where lessondate='"&lessondate&"'"
                  */               // if(tSeltype.equalsIgnoreCase("Translations"))
                   // sql = "select distinct translations from A_English where lessondate = '"+tLessonDate+"'";
                   // else if(tSeltype.equalsIgnoreCase("classRoom"))
                    //sql = "select distinct classroom from A_English  lessondate = '"+tLessonDate+"'";
                    //else if(tSeltype.equalsIgnoreCase("Sentence_4u"))
                    //sql = "select distinct sentence_4u from A_English where  lessondate = '"+tLessonDate+"'";
                   //  }
              }
            try
            {
                conn = db.getConnection();
                if ( _log.isDebugEnabled() )
                {
                    _log.debug("SQL is :"+sql);
                }
                DBSelection s = new DBSelection( conn, sql );
                int rowCount = s.rowCount();
                if ( rowCount < 0 )
                {
                    String errMsg = "查询A_English错误:";
                    _log.error( errMsg + s.getExceptionStackTrace() );
                    throw new GWException ( errMsg, s.getExceptionStackTrace() );
                }            magazineShow = new TmagazineMidUpShow[rowCount];
                for (int i = 0; i < rowCount; i ++)
                {
                  TmagazineMidUpShow l = new TmagazineMidUpShow();
                  //String tempstr;
            l.englishTitle=MiscTools.getString( s.getItem( i + 1, "englishTitle" ), "" );
    l.chineseTitle=MiscTools.getString( s.getItem( i + 1, "chineseTitle" ), "" );
    l.lessonDate  =MiscTools.getString( s.getItem( i + 1, "lessonDate" ), "" );
    l.picPath     =MiscTools.getString( s.getItem( i + 1, "picPath" ), "" );
    l.audioPath   =MiscTools.getString( s.getItem( i + 1, "audioPath" ), "" );
    l.lessonContent=MiscTools.getString( s.getItem( i + 1, "audioPath" ), "" );
    l.sytaxBBS             =MiscTools.getString( s.getItem( i + 1, "sytaxBBS" ), "" );
    l.listeningExer1       =MiscTools.getString( s.getItem( i + 1, "listeningExer1" ), "" );
    l.listeningExer2       =MiscTools.getString( s.getItem( i + 1, "listeningExer2" ), "" );
    l.sentence             =MiscTools.getString( s.getItem( i + 1, "sentence" ), "" );
    l.listeningExer1_Answer=MiscTools.getString( s.getItem( i + 1, "listeningExer1_Answer" ), "" );
    l.listeningExer2_Answer=MiscTools.getString( s.getItem( i + 1, "listeningExer2_Answer" ), "" );
    l.sentence_Answer      =MiscTools.getString( s.getItem( i + 1, "sentence_Answer" ), "" );
    l.translations         =MiscTools.getString( s.getItem( i + 1, "translations" ), "" );
    l.vocabulary           =MiscTools.getString( s.getItem( i + 1, "vocabulary" ), "" );
    l.temp1                =MiscTools.getString( s.getItem( i + 1, "temp1" ), "" );
    l.temp2                =MiscTools.getString( s.getItem( i + 1, "temp2" ), "" );              magazineShow[i] = l;
                }
                return magazineShow;
            }
            catch ( GWException je )
            {
                String errMsg = "JDBC连接错误:";
                _log.error(errMsg+je.getErrMsg());
                throw new GWException( errMsg, je.getErrMsg() );
            }
            finally
            {
                db.close();
            }
        }
    ////////////////////////////////////////////////////////////////////////
    public TmagazineMidUpShow[] queryTmagazineShow (String tLessonDate) throws GWException
        {  if(!SysConfValidator.verifyTime())
            {
                throw new GWException("系统已经失效。");
            }
           if(tLessonDate.equals(null))
            {
                throw new GWException("错误的参数:日期比能为空不能为空。");
            }        return queryTmagazineShow("",tLessonDate);
        }
    ////////////////////////////////////////////////////////////////////////
      

  4.   


    ////////////////////////////////////////////////////////////////////////    public TmagazineMidUpDetail[] queryTmagazineDetail ( String tSeltype,String tLessonDate) throws GWException
        {
            if (tLessonDate == null)
            {
                throw new GWException("错误的参数:参数不能为空。");
            }
            if(!SysConfValidator.verifyTime())
            {
                throw new GWException("系统已经失效。");
            }
            DatabaseConn db = new DatabaseConn();
            Connection conn = null;
            TmagazineMidUpDetail magazineDetail[];
            String sql="";         if(tSeltype==null||tSeltype.equals(""))
              sql = "select distinct  * FROM TbA_EnglishDetail where lessondate = '"+tLessonDate+"' order by lessondate desc";
             else{
               if (tSeltype.equalsIgnoreCase("Text"))
                   sql = "select Id,textBody,audioPath from TbA_EnglishDetail where lessondate='"+tLessonDate+"' and type='text' order by Id";
                    else if(tSeltype.equalsIgnoreCase("TextExer"))
                     sql = "select distinct audioPath from TbA_EnglishDetail where lessondate='"+tLessonDate+"' and type='课文讲解'";
                    else if(tSeltype.equalsIgnoreCase("trainingRoom"))
                     sql = "select distinct type,textBody,questionCount,note from TbA_EnglishDetail where lessondate='"+tLessonDate+"' and class='EnglishPractice' and type='英语练功房'";
                    else if(tSeltype.equalsIgnoreCase("translationExer"))
                     sql = "select distinct type,textBody,questionCount,note from TbA_EnglishDetail where lessondate='"+tLessonDate+"' and class='EnglishPractice' and type='翻译练习'";
                    else if(tSeltype.equalsIgnoreCase("scenicDialog"))
                     sql = "select distinct type,textBody,questionCount,note from TbA_EnglishDetail where lessondate='"+tLessonDate+"' and class='EnglishPractice' and type='情境对话小测验'";
                   else if(tSeltype.equalsIgnoreCase("Vocabulary"))
                     sql = "select distinct Id,textBody,audioPath from TbA_EnglishDetail where lessondate='"+tLessonDate+"' and type='Vocabulary' and Id<>0 order by Id";
                   else if(tSeltype.equalsIgnoreCase("listeningExer1"))
                     sql = "select distinct Type,Id,textBody,audioPath,questionCount,note from TbA_EnglishDetail where lessondate='"+tLessonDate+"' and class='ListeningExer' and type='听力练习基础篇' and Id=0 order by Id";
                    else if(tSeltype.equalsIgnoreCase("listeningExer2"))
                     sql = "select distinct Type,Id,textBody,audioPath,questionCount,note from TbA_EnglishDetail where lessondate='"+tLessonDate+"' and class='ListeningExer' and type='听力练习活用篇' and Id=0 order by Id";         }        try
            {
                conn = db.getConnection();
                if ( _log.isDebugEnabled() )
                {
                    _log.debug("SQL is :"+sql);
                }
                DBSelection s = new DBSelection( conn, sql );
                //DBSelection sNote = new DBSelection( conn, sqlNote );
                int rowCount = s.rowCount();
                if ( rowCount < 0 )
                {
                    String errMsg = "查询A_EnglishDetail错误:";
                    _log.error( errMsg + s.getExceptionStackTrace() );
                    throw new GWException ( errMsg, s.getExceptionStackTrace() );
                }            magazineDetail = new TmagazineMidUpDetail[rowCount];
                for (int i = 0; i < rowCount; i ++)
                {
                  TmagazineMidUpDetail l = new TmagazineMidUpDetail();
                  String info = null;
                  String tempstr;
                  if (weight)
                    info ="A_EnglishDetail".toLowerCase() ;
            l.dbClass= MiscTools.getString(s.getItem( i + 1, "dbClass" ), "" );
    l.type = MiscTools.getString( s.getItem( i + 1, "type" ), "" );
    l.EnglishTitle = MiscTools.getString(s.getItem( i + 1, "englishTitle" ), "" );
    l.ChineseTitle = MiscTools.getString( s.getItem( i + 1, "ChineseTitle" ), "" );
    l.lessondate = MiscTools.getString( s.getItem( i + 1, "lessonDate" ), "" );
    tempstr =  (s.getItem( i + 1, "Id" ));
            if (tempstr != null && !tempstr.equals(""))
               l.Id = Integer.parseInt(tempstr );
    l.textBody= MiscTools.getString( s.getItem( i + 1, "textBody" ), "" );
    l.audioPath= MiscTools.getString( s.getItem( i + 1, "audioPath" ), "" );
    l.questionCount= MiscTools.getString( s.getItem( i + 1, "questionCount") , "" );
    l.picPath= MiscTools.getString( s.getItem( i + 1, "picPath" ), "" );
    l.note= MiscTools.getString(s.getItem( i + 1, "note" ), "" );
                 ///////////////////////
               magazineDetail[i] = l;
                }
                return magazineDetail;
            }
            catch ( GWException je )
            {
                String errMsg = "JDBC连接错误:";
                _log.error(errMsg+je.getErrMsg());
                throw new GWException( errMsg, je.getErrMsg() );
            }
            finally
            {
                db.close();
            }
        }
    //////////////////////////////////////////////////////////////////
        public TmagazineMidUpDetail[] queryTmagazineDetail (String tLessonDate) throws GWException
        {  if(!SysConfValidator.verifyTime())
            {
                throw new GWException("系统已经失效。");
            }
           if(tLessonDate.equals(null))
            {
                throw new GWException("错误的参数:日期比能为空不能为空。");
            }        return queryTmagazineDetail("",tLessonDate);
        }
    ////////////////////////////////////////////////////////////////////////
    }
      

  5.   

    天地无用: 我想这样封装后,在JSP中取数会不会方便些?猛将兄:您那样好是好,但是那个实际还是个RESULTSET结果集呀东东树,您好:
           您给我的代码太长了,能不能把它缩减一下,我看不大明白----你是想发给我一个可以直接复制使用的方法呢,还是想告诉我该怎么样去实现把结果封于BEAN中?
    我知道我可以把RESULTSET中的数据一个一个地取出来,再一个一个地放入BEAN中,但是我的本意是觉得这样劳动量太大,不想这么干,我想知道我没有什么可以继承的现成的方法,让我直接把查询结果放入BEAN中,使得我自己编写的代码看起来简洁明了
      

  6.   

    把结果集  装到 Vector() 里然后用循环 读出 elementAt(i).. 这种方法是最好的。
      

  7.   

    恩我也经常用小土豆仙说的方法,但是这样有一个问题,你不知道查询数据得到的类型,所以可以自己写一个封装查询的SearchSet类
    class SearchSet{
        Vector dateType;//标志数据类型,在从数据库中查询返回的时候,根据字段类型设置,
                       //在取得时候,就判断这个字段来强制转换类型到原来
        Vector dateValue;//保存数据的结构
    }
      

  8.   

    _littlebee()
    所以呢,我会另外写个接口..把所有需要取得数据类型,都放在接口里定义...jive就是这样做的啦
      

  9.   

    你看看DAO模式不就可以了。每条数据影射一个实例,在将他装载到一个VECTOR中,用ITERATOR循环出来就可以了。
      

  10.   

    把结果装到VECTOR中,和把结果装到RESULTSET中,所用到的数据连接和数据访问语句是不一样的吗?如果是不一样的,能不能把封装到VECTOR中的数据库连接和访问语句给我呢?我现在的语句,是把数据库查询结果保存到ResultSet结果集中去了呀
      

  11.   

    /*****
    把结果装到VECTOR中,和把结果装到RESULTSET中,所用到的数据连接和数据访问语句是不一样的吗?
    ***/
    当然不一样,装到vector中,就可以把datasource给close了.否则就要在jsp中close了(有人常忘了)