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" "http://www.springframework.org/dtd/spring-beans.dtd">

<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

posted on 2007-01-11 17:21 Kim' 阅读(2282) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 
jj