`
thinktothings
  • 浏览: 766734 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

spring2.0.8_datasource

 
阅读更多

spring连接基本的数据源

 

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.jdbc.object.SqlUpdate;


public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Test test=new Test();
		
		
		JdbcTemplate jt = new JdbcTemplate();
		jt.setDataSource(test.getDataSource());
	
		SqlUpdate su = new SqlUpdate();
		su.setJdbcTemplate(jt);
		su.setSql("UPDATE  ct_cuinfo t set vc2cuname='bbb' where numcuguid=1068");
		su.compile();
		su.update();
		
	
	}
	
	
	
	/**
	 * 创建数据源
	 * @return
	 */
	public DataSource getDataSource(){
		DriverManagerDataSource dataSource = new DriverManagerDataSource();
		dataSource.setDriverClassName("oracle.jdbc.driver.OracleDriver");
		dataSource.setUrl("jdbc:oracle:thin:@172.16.49.55:1521:orcl");
		dataSource.setUsername("tht");
		dataSource.setPassword("tht");
		return dataSource;
	}

}

 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics