-
/**
-
* Copyright: Copyright (c) 2005-2005
-
* Company: JavaResearch(http://www.javaresearch.org)
-
*/
-
package
org.javaresearch.jerch;
-
-
import
java.sql.Connection;
-
import
java.sql.PreparedStatement;
-
import
java.sql.SQLException;
-
-
/**
-
* 創建PreparedStatement的接口定義。
-
* 最后更新日期:2005年3月28日
-
* @author cherami
-
*/
-
public
interface
PreparedStatementCreator
{
- ? /**
-
?? * 從數據庫連接中創建一個PreparedStatement。
-
?? * @param con 數據庫連接
-
?? * @return 創建好的PreparedStatement
-
?? * @throws SQLException
-
?? */
- ? publicPreparedStatement createPreparedStatement(Connection con) throwsSQLException;
- }
-
- 使用實例:
- 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
華夢行 閱讀(4165)
評論(0) 編輯 收藏 所屬分類:
Spring