KK

          Kim-'s-Blog.Object-Everything.I'm POJO.

          .紀-錄.爲了忘卻的記憶..真的勇士,要敢于直面遇到的問題,敢于正視繁雜的原碼......在實踐中積累!

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            74 Posts :: 1 Stories :: 70 Comments :: 0 Trackbacks

          Spring JDBC 很好用。
          -------------------------------
          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "

          <beans>
          ?<bean id="dataSource"
          ??class="org.springframework.jdbc.datasource.DriverManagerDataSource"
          ??abstract="false" singleton="true" lazy-init="default"
          ??autowire="default" dependency-check="default">
          ?<property name="driverClassName"><value>oracle.jdbc.OracleDriver</value></property>
          ?<property name="url"><value>jdbc:oracle:thin:@10.240.144.11:1521:XYMES</value></property>
          ?<property name="username"><value>reel</value></property>
          ?<property name="password"><value>reel</value></property>
          ?</bean>
          </beans>
          ------------------------------------
          package com.kim.spring;
          import java.util.List;

          import javax.sql.DataSource;
          import org.springframework.context.ApplicationContext;
          import org.springframework.context.support.FileSystemXmlApplicationContext;
          import org.springframework.jdbc.core.JdbcTemplate;

          public class Test
          {

          ?/**
          ? * @param args
          ? */
          ?public void aMethod()throws Exception
          ?{?
          ??ApplicationContext ac=new FileSystemXmlApplicationContext("F:\\kim\\kimjob\\springkim\\src\\applicationContext.xml");
          ??DataSource dataSource=(DataSource)ac.getBean("dataSource");
          ??JdbcTemplate jt=new JdbcTemplate(dataSource);
          ??List l= jt.queryForList("select * from abc");
          ??System.out.println(l.get(0).toString());
          ??System.out.println(l.get(0));
          ??int i= jt.update("update abc set bb='8'");
          ??System.out.println(i);
          ??
          ?}
          ?public static void main(String[] args)
          ?{
          ??// TODO Auto-generated method stub
          ??Test t=new Test();
          ??try
          ??{
          ???t.aMethod();
          ??} catch (Exception e)
          ??{
          ???// TODO: handle exception
          ???e.printStackTrace();
          ??}
          ?}
          }
          ---------------------------------
          結果:
          log4j:WARN No appenders could be found for logger (org.springframework.core.CollectionFactory).
          log4j:WARN Please initialize the log4j system properly.
          {AA=2, BB=8, CC=2}
          1


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


          網站導航:
           
          jj
          主站蜘蛛池模板: 青阳县| 汝南县| 台江县| 凤凰县| 油尖旺区| 商洛市| 彩票| 南涧| 开平市| 桂阳县| 宁津县| 错那县| 罗甸县| 平潭县| 朝阳县| 阿合奇县| 岐山县| 睢宁县| 喀什市| 固镇县| 香港| 屯昌县| 沾益县| 河津市| 肇庆市| 韩城市| 客服| 新巴尔虎右旗| 林周县| 昌黎县| 高雄市| 容城县| 阿克| 历史| 五台县| 图木舒克市| 时尚| 新和县| 那坡县| 闵行区| 石河子市|