随笔-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 华梦行 阅读(4140) 评论(0)  编辑  收藏 所属分类: Spring

只有注册用户登录后才能发表评论。


网站导航: