<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 華夢行 閱讀(295) 評論(0)  編輯  收藏 所屬分類: Spring
    主站蜘蛛池模板: 女人被弄到高潮的免费视频| 亚洲精品无码日韩国产不卡?V| 好吊妞视频免费视频| 亚洲美女自拍视频| 最近免费中文在线视频| 亚洲色av性色在线观无码| 亚洲一区免费视频| 亚洲人成无码网WWW| ww在线观视频免费观看w| 国产亚洲精品看片在线观看| 13小箩利洗澡无码视频网站免费| 日韩视频免费在线| 国产精品亚洲综合一区在线观看| 免费看国产一级片| 国产区在线免费观看| 日本免费人成黄页在线观看视频| 亚洲Av无码国产一区二区| 国产精品另类激情久久久免费| 黄色a级片免费看| 永久黄网站色视频免费| 亚洲人成网站在线播放影院在线| 亚洲av永久无码一区二区三区| 国产精品免费_区二区三区观看| 成人午夜影视全部免费看| 女人18毛片a级毛片免费| 美女露隐私全部免费直播| 综合久久久久久中文字幕亚洲国产国产综合一区首 | 91情国产l精品国产亚洲区| 97性无码区免费| 亚洲短视频男人的影院| 久久精品无码专区免费| 亚洲丝袜美腿视频| 日韩a在线观看免费观看| 中国一级特黄高清免费的大片中国一级黄色片| 亚洲AV永久纯肉无码精品动漫| 国产福利电影一区二区三区,免费久久久久久久精 | 国产成人精品高清免费| a在线免费观看视频| 亚洲日韩一中文字暮| 亚洲综合另类小说色区| 久久久久久久免费视频|