<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

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

    package org.springframework.samples;

    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;

    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.beans.factory.ListableBeanFactory;
    import org.springframework.beans.factory.generic.GenericBeanFactoryAccessor;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import org.springframework.dao.DataAccessException;
    import org.springframework.jdbc.core.ColumnMapRowMapper;
    import org.springframework.jdbc.core.ConnectionCallback;
    import org.springframework.jdbc.core.JdbcTemplate;
    import org.springframework.jdbc.core.PreparedStatementCallback;
    import org.springframework.jdbc.core.PreparedStatementCreator;
    import org.springframework.jdbc.core.PreparedStatementSetter;
    import org.springframework.jdbc.core.ResultSetExtractor;
    import org.springframework.jdbc.core.RowCallbackHandler;
    import org.springframework.jdbc.core.RowCountCallbackHandler;
    import org.springframework.jdbc.core.RowMapper;
    import org.springframework.jdbc.core.StatementCallback;
    import org.springframework.jdbc.support.JdbcUtils;
    import org.springframework.samples.petclinic.Person;

    /**
    ?*
    ?* @author worldheart
    ?*
    ?*/
    public class MainTestForJdbcTemplate {

    ?private static final Log log = LogFactory.getLog(MainTestForJdbcTemplate.class);
    ?
    ?public static void main(String[] args) {??
    ??ListableBeanFactory cbf = new ClassPathXmlApplicationContext("ac1.xml");??
    ??GenericBeanFactoryAccessor gbfa = new GenericBeanFactoryAccessor(cbf);
    ??
    ??JdbcTemplate jt = gbfa.getBean("jdbcTemplate");
    ??
    ??jt.execute(new ConnectionCallback(){
    ???public Object doInConnection(Connection con) throws SQLException, DataAccessException {
    ????System.out.println(con.getMetaData().getDriverName());
    ????return null;
    ???}
    ??});
    ??
    ??List nameList = (List)jt.execute(new StatementCallback(){
    ???public Object doInStatement(Statement stmt) throws SQLException, DataAccessException {
    ????System.out.println(stmt.getConnection().getMetaData().getDatabaseProductVersion());
    ????List<String> nameList = new ArrayList<String>();
    ????ResultSet rs = null;
    ????try{
    ?????rs = stmt.executeQuery("select name from types");
    ?????while(rs.next()){
    ??????nameList.add(rs.getString("name"));
    ?????}
    ????}finally{
    ?????JdbcUtils.closeResultSet(rs);
    ????}
    ????return nameList;
    ???}
    ??});
    ??System.out.println(nameList);
    ??
    ??List perList = (List)jt.query("select * from vets",
    ????new ResultSetExtractor(){
    ??????public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
    ???????List<Person> personList = new ArrayList<Person>();
    ???????while(rs.next()){
    ????????Person per = new Person();
    ????????per.setId(rs.getInt("id"));
    ????????per.setFirstName(rs.getString("first_name"));
    ????????per.setLastName(rs.getString("last_name"));
    ????????personList.add(per);
    ???????}
    ???????return personList;
    ????}
    ??});
    ??for(Iterator iterator = perList.iterator(); iterator.hasNext();){
    ???Person person = (Person)iterator.next();
    ???System.out.println(person.getId() + "," + person.getFirstName() + "," + person.getLastName());
    ??}

    ??final List<Person> pSonList = new ArrayList<Person>();
    ??jt.query("select * from vets", new RowCallbackHandler(){
    ???public void processRow(ResultSet rs) throws SQLException {
    ????Person per = new Person();
    ????per.setId(rs.getInt("id"));
    ????per.setFirstName(rs.getString("first_name"));
    ????per.setLastName(rs.getString("last_name"));
    ????pSonList.add(per);
    ???}
    ??});
    ??for(Person pSon: pSonList){
    ???System.out.println(pSon.getId() + "," + pSon.getFirstName() + "," + pSon.getLastName());
    ??}
    ??
    ??RowCountCallbackHandler rcch = new RowCountCallbackHandler();
    ??jt.query("select * from vets", rcch);
    ??for(String colName: rcch.getColumnNames())
    ???System.out.println(colName);
    ??for(int colType: rcch.getColumnTypes())
    ???System.out.println(colType);
    ??System.out.println(rcch.getColumnCount());
    ??System.out.println(rcch.getRowCount());
    ??
    ??List vetsList = (List)jt.query("select * from vets",
    ????new RowMapper(){
    ?????public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
    ??????Person pers = new Person();
    ??????pers.setId(rs.getInt("id"));
    ??????pers.setFirstName(rs.getString("first_name"));
    ??????pers.setLastName(rs.getString("last_name"));
    ??????return pers;
    ?????}
    ??});
    ??System.out.println(vetsList);
    ??
    ??ColumnMapRowMapper cmrw = new ColumnMapRowMapper();
    ??List vList = (List)jt.query("select * from vets", cmrw);
    ??System.out.println(vList);
    ??
    ??System.out.println(jt.queryForInt("select count(*) from vets where id = ?",
    ????new Object[]{3}));
    ??????
    ??jt.execute("update owners set address = 'GuangZhou' where telephone = ?",
    ????new PreparedStatementCallback(){
    ?????public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
    ??????ps.setString(1, "16068008");
    ??????ps.addBatch();
    ??????ps.setString(1, "6085555487");
    ??????ps.addBatch();
    ??????return ps.executeBatch();
    ?????}
    ??});
    ??
    ??System.out.println(jt.query("select address from owners where first_name = ? and last_name = ?",
    ????new PreparedStatementSetter(){
    ?????public void setValues(PreparedStatement ps) throws SQLException {
    ??????ps.setString(1, "Jeff");
    ??????ps.setString(2, "Black");
    ?????}
    ????},
    ????new RowMapper(){
    ?????public Object mapRow(ResultSet rs, int rowNum) throws SQLException {??????
    ??????return rs.getString("address");
    ?????}
    ????}));
    ??
    ??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-11 11:22 華夢行 閱讀(296) 評論(0)  編輯  收藏 所屬分類: Spring
    主站蜘蛛池模板: 亚洲乱码一区二区三区国产精品| 亚洲Av综合色区无码专区桃色 | 在线人成精品免费视频| 亚洲日韩精品射精日| 成人黄网站片免费视频| 亚洲大尺度无码专区尤物| 日韩电影免费在线观看| 亚洲色欲色欲综合网站| 2022久久国产精品免费热麻豆| 亚洲高清中文字幕| 性xxxxx免费视频播放| 亚洲熟妇丰满xxxxx| 日日夜夜精品免费视频| 色老头综合免费视频| 国产av无码专区亚洲av果冻传媒| 国产美女视频免费观看的网站 | 亚洲天堂福利视频| 巨胸喷奶水视频www网免费| 亚洲av无码有乱码在线观看| 国产伦精品一区二区三区免费迷| 特级毛片在线大全免费播放| 亚洲人成精品久久久久| 久久精品国产免费观看三人同眠| 中文字幕亚洲男人的天堂网络| 暖暖在线日本免费中文| 亚美影视免费在线观看| 久久精品国产亚洲av麻豆小说| 最近的免费中文字幕视频| 美女黄频a美女大全免费皮| 亚洲精品无码久久久影院相关影片| 91人成网站色www免费下载| 亚洲欧洲免费无码| 亚洲色WWW成人永久网址| 国产精品成人免费福利| 亚洲国产区男人本色| 精品亚洲综合在线第一区| 免费电影在线观看网站| 国产无限免费观看黄网站| 亚洲Av高清一区二区三区| 爱情岛论坛网亚洲品质自拍| 国产精品视频免费|