隨筆-295  評論-26  文章-1  trackbacks-0
          1. /**


          2. * Copyright: Copyright (c) 2005-2005
          3. * Company: JavaResearch(http://www.javaresearch.org)
          4. */
          5. package org.javaresearch.jerch;

          6. import java.sql.Connection;
          7. import java.sql.PreparedStatement;
          8. import java.sql.SQLException;

          9. /**
          10. * 創建PreparedStatement的接口定義。
          11. * 最后更新日期:2005年3月28日
          12. * @author cherami
          13. */
          14. public interface PreparedStatementCreator {
          15. ? /**
          16. ?? * 從數據庫連接中創建一個PreparedStatement。
          17. ?? * @param con 數據庫連接
          18. ?? * @return 創建好的PreparedStatement
          19. ?? * @throws SQLException
          20. ?? */
          21. ? publicPreparedStatement createPreparedStatement(Connection con) throwsSQLException;
          22. }
          23. 使用實例:
          24. jt? jdbctemplate:
            ??System.out.println(jt.execute(
            ????new PreparedStatementCreator(){
            ?????public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
            ??????return con.prepareStatement("select address from owners");
            ?????}
            ????},
            ????new PreparedStatementCallback(){
            ?????public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
            ??????List<String> list = new ArrayList<String>();
            ??????ResultSet rs = null;
            ??????try{
            ???????rs = ps.executeQuery();
            ???????while(rs.next()){
            ????????list.add(rs.getString("address"));
            ???????}
            ??????}finally{
            ???????JdbcUtils.closeResultSet(rs);
            ??????}
            ??????return list;
            ?????}
            ????}));


          大盤預測 國富論
          posted on 2007-09-10 10:38 華夢行 閱讀(4178) 評論(0)  編輯  收藏 所屬分類: Spring
          主站蜘蛛池模板: 松溪县| 乌拉特中旗| 江油市| 龙州县| 婺源县| 鹤庆县| 建瓯市| 离岛区| 同仁县| 禹州市| 吴堡县| 宁陕县| 金塔县| 明星| 磐石市| 抚顺县| 皋兰县| 儋州市| 濮阳县| 武清区| 华宁县| 南阳市| 包头市| 昆明市| 厦门市| SHOW| 沂水县| 疏勒县| 福鼎市| 图木舒克市| 宁河县| 徐州市| 楚雄市| 历史| 泰和县| 诏安县| 莱州市| 宜城市| 咸丰县| 灯塔市| 通化县|