1:Java文件JdbcTemplateDemo.java
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
public class JdbcTemplateDemo
{
public static void main(String args[])
{
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("oracle.jdbc.OracleDriver");
dataSource.setUrl("jdbc:oracle:thin:scott/tiger@192.168.126.6:1521:dbname");
dataSource.setUsername("scott");
dataSource.setPassword("tiger");
JdbcTemplate jt = new JdbcTemplate(dataSource);
jt.execute("insert into dept(deptno, dname, loc) values(90, 'RD', 'BEIJING')");
// jt.execute("delete from dept where dname='RD'");
return ;
}
}
2:设置CLASSPATH环境变量
把spring.jar log4j-1.2.9.jar commons-logging.jar ojdbc14.jar添加到环境变量
3:拷贝dtd文件spring-beans.dtd
4:编写log4j配置文件log4j.properties
5:编译javac JdbcTemplateDemo.java
6:执行java JdbcTemplateDemo能看到DEPT表中增加了记录
阅读(1052) | 评论(0) | 转发(0) |