隨筆-72  評論-63  文章-0  trackbacks-0
          ???? < bean? id ="dataSource" ?class ="org.springframework.jdbc.datasource.DriverManagerDataSource" ?destroy-method ="close" >
          ????????
          < property? name ="driverClassName" >< value > org.hibernate.dialect.MySQLDialect </ value ></ property >
          ????????
          < property? name ="url" >
          ????????????
          < value > jdbc:mysql://127.0.0.1:3306/springtest&useUnicode=true &amp; characterEncoding=utf8 </ value >
          ????????????
          </ property >
          ????????
          < property? name ="username" >< value > root </ value ></ property >
          ????????
          < property? name ="password" >< value ></ value ></ property >
          ????
          </ bean >

          ??? 然后在轉換程序里面get這個dataSource,new 一個JdbcTemplate(dataSource)

          ???? public ? void ?testCopyData()? throws ?Exception{
          ????????DataSource?ds?
          = ?(DataSource)applicationContext.getBean( " dataSource " );
          ????? ???JdbcTemplate?jt? = ? new ?JdbcTemplate(ds);
          ????????System.out.println(
          " Total?posts: " + jt.queryForInt( " select?count(*)?from?wp_posts " ));
          ????????assertNotNull(ds);
          ????????
          ????????List?cates?
          = ?jt.queryForList( " select?*?from?wp_categories " );
          ????????
          int ?i = ? 0 ;
          ????????
          for (Iterator?ite? = ?cates.iterator();?ite.hasNext();){
          ????????????i
          ++ ;
          ????????????Map?result?
          = ?(Map)?ite.next();
          ????????????Category?cate?
          = ? new ?Category();
          ????????????cate.setName((String)result.get(
          " cat_name " ));
          ????????????cate.setOrder(i);
          ????????????
          if (i == 1 )
          ????????????????cate.setDefaultCategory(
          true );
          ????????????cateManager.saveCategory(cate);
          ????????????System.out.println(
          " cat_name: " + result.get( " cat_name " ) + " \n " );
          ????????}
          ????}
          posted on 2006-05-01 23:54 船長 閱讀(328) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 天柱县| 永春县| 枣庄市| 清原| 德钦县| 黑龙江省| 大英县| 黔西| 比如县| 武川县| 蒙阴县| 蕲春县| 拉孜县| 车险| 福海县| 秦安县| 南汇区| 太仓市| 万年县| 凌源市| 永清县| 德格县| 衢州市| 棋牌| 惠东县| 海兴县| 定结县| 方正县| 潼关县| 平潭县| 会宁县| 桐城市| 大渡口区| 顺昌县| 什邡市| 宁河县| 南开区| 丰镇市| 石家庄市| 丰县| 常山县|