File: context.xml
"http://www.springframework.org/dtd/spring-beans.dtd">
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
sun.jdbc.odbc.JdbcOdbcDriver
jdbc:odbc:test
root
sql
File: Main.java
import javax.sql.DataSource;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.JdbcTemplate;
public class Main {
public static void main(String[] args) throws Exception {
BeanFactory factory = new XmlBeanFactory(new ClassPathResource("context.xml"));
Dataconimpl bean1 = (Dataconimpl) factory.getBean("datacon");
JdbcTemplate jt = new JdbcTemplate(bean1.dbcon());
jt.execute("delete from table1 ");
jt.execute("update table1 set table1.place='' ");
}
}
class Dataconimpl implements Datacon {
private DataSource dataSource;
public void setDataSource(DataSource ds) {
dataSource = ds;
}
public DataSource dbcon() {
return dataSource;
}
}
interface Datacon {
public DataSource dbcon();
}
Spring-UpdateDeleteStatementsWithJdbcTemplate.zip( 2,894 k)