隨筆-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 >

          ??? 然后在轉(zhuǎn)換程序里面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 船長 閱讀(326) 評論(0)  編輯  收藏

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 龙山县| 中宁县| 安陆市| 巨鹿县| 东光县| 凯里市| 凤冈县| 夏邑县| 常宁市| 万载县| 濉溪县| 林芝县| 衡南县| 行唐县| 楚雄市| 平阳县| 金湖县| 冕宁县| 廊坊市| 深州市| 同江市| 东兰县| 英吉沙县| 晋中市| 鄱阳县| 泌阳县| 东乌| 微博| 西峡县| 宜都市| 张家界市| 交口县| 拉孜县| 天等县| 遂溪县| 黑河市| 托里县| 花垣县| 宜兴市| 伊吾县| 湘潭县|