<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
    主站蜘蛛池模板: 免费观看的毛片手机视频| 成人性生交大片免费看无遮挡| 拔擦拔擦8x华人免费久久| 亚洲一级毛片中文字幕| 91麻豆最新在线人成免费观看| 久久久久久亚洲Av无码精品专口 | 亚洲AV无码国产在丝袜线观看| av片在线观看永久免费| 亚洲精品无码AV中文字幕电影网站| 免费无码一区二区| 亚洲一区二区三区在线视频| 精选影视免费在线 | 久久久久久a亚洲欧洲aⅴ| 污污网站免费观看| 亚洲天堂中文字幕| A在线观看免费网站大全| 四虎必出精品亚洲高清| 日本二区免费一片黄2019| 免费一区二区三区在线视频| 亚洲日本中文字幕天堂网| 国内少妇偷人精品视频免费| 亚洲日韩中文字幕天堂不卡| 91免费精品国自产拍在线不卡| 亚洲色大成网站www久久九| 亚洲A∨精品一区二区三区| 一级毛片免费在线播放| 亚洲国产天堂在线观看| 成年女人免费视频播放77777| 黄网站色视频免费看无下截| 亚洲乱码精品久久久久..| 在线永久免费的视频草莓| 美女露隐私全部免费直播| 国产亚洲精AA在线观看SEE| 国产精品怡红院永久免费| 日韩亚洲翔田千里在线| 亚洲AV无码成人精品区天堂| 免费国产黄线在线观看 | 少妇亚洲免费精品| 亚洲av成人无码久久精品| 女人18毛片水最多免费观看| 99视频在线观看免费|