posts - 84,  comments - 54,  trackbacks - 0

          ??????? 我分別寫了一個顯示一個表(example table)中所有內容的jsp文件和 按輸入的 id查詢 emample當中的數據的jsp文件。

          ?????? 中間我用到了DAO層
          ?????? 其中顯示example當中所有的內容代碼如下

          ?1 ???????? try ? {
          ?2 ?????????ResultSet?rs? = ?db.query(sql);
          ?3
          ?4 ?????????? while ?(rs.next())? {
          ?5
          ?6 ?????????????Student?student? = ? new ?Student();
          ?7
          ?8 ??????????student.setStu_id(rs.getString( 1 ));
          ?9 ??????????student.setStu_name(rs.getString( 2 ));
          10 ??????????student.setClass_id(rs.getString( 3 ));
          11 ???????????student.setClass_name(rs.getString( 4 ));
          12
          13 ??????????list.add(student);
          14 ?????????}

          15 ???
          16 ??????????rs.close();
          17 ???
          18 ???
          19 ???????}
          ? catch ?(SQLException?e)? {
          20 ??????? // ?TODO?自動生成?catch?塊
          21 ???????e.printStackTrace();
          22 ??????}

          23



          而查詢功能時,由于是顯示一條記錄,不是顯示所有記錄,所有有點粗心
          忘了寫rs.next()所以調了很久還是沒有調出來,rs.next()的作用就是使指向記錄集的指針往下移動一行,如果有記錄的話則返回真,否則返回否

          ?

          ?1 ????????????ResultSet?rs? = ?db.query(sql);
          ?2 ????????????
          ?3 ????????????ArrayList?list? = ? new ?ArrayList();
          ?4 ????????????
          ?5 ???????????? while (rs.next()) {
          ?6 ????????????????Student?student? = ? new ?Student();?
          ?7 ????????????????student.setStu_id(rs.getString( 1 ));
          ?8 ????????????????student.setStu_name(rs.getString( 2 ));
          ?9 ????????????????student.setClass_id(rs.getString( 3 ));
          10 ????????????????student.setClass_name(rs.getString( 4 ));
          11 ????????????????list.add(student);
          12 ????????????}

          13 ????????????
          14 ????????????rs.close();
          15 ???????????? return ?list;

          ??? 當然,出現ResultSet用的錯誤的還有其他很多問題,具體問題還是要具體分析,我的經歷供大家參考!!
          posted on 2006-10-15 00:30 JavaCoffe 閱讀(1320) 評論(0)  編輯  收藏 所屬分類: J2EE 學習
          <2006年10月>
          24252627282930
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          常用鏈接

          留言簿(5)

          隨筆分類(80)

          收藏夾(1)

          最新隨筆

          積分與排名

          • 積分 - 58640
          • 排名 - 893

          最新評論

          閱讀排行榜

          主站蜘蛛池模板: 永嘉县| 东安县| 凌海市| 饶平县| 崇阳县| 昔阳县| 桃园市| 凌云县| 安达市| 丹凤县| 祁门县| 广宗县| 菏泽市| 玛纳斯县| 博罗县| 苏尼特右旗| 黔东| 东丽区| 临汾市| 灵寿县| 普洱| 澄江县| 巴东县| 贵溪市| 桐乡市| 崇文区| 绥阳县| 长汀县| 哈巴河县| 桦甸市| 宾川县| 兴国县| 新和县| 松滋市| 蓬溪县| 河间市| 三明市| 绿春县| 临猗县| 开平市| 娱乐|