Pure JDBC operation, perhaps better for some projects, the Spring JDBC framework lets you not care about connection, Statement, ResultSet. Defining data Sources example of Spring transaction programming<BeanID= "DataSource"class= "Org.springframework.jndi.JndiObjectFactoryBean">examples of spring transaction programming< Propertyname= "Jndiname">examples of spring transaction programming<value>Java:/comp/env/jdbc/oracle</value>examples of spring transaction programming</ Property>examples of spring transaction programming</Bean>defining the transaction manager<BeanID= "TransactionManager"class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager"> < Propertyname= "DataSource"ref= "DataSource" /></Bean>example of defining daospring transaction programming<BeanID= "Customerdao"class= "Com.waterye.dao.impl.CustomerDAOImpl">examples of spring transaction programming< Propertyname= "DataSource"ref= "DataSource" />examples of spring transaction programming< Propertyname= "TransactionManager"ref= "TransactionManager" />examples of spring transaction programming</Bean>public class Customerdaoimpl extends Jdbcdaosupport implements Customerdao {private DataSource DataSource; Pirvate TransactionManager TransactionManager; public void Setdatasource (DataSource DataSource) {this.datasource = DataSource; } public void Settransactionmanager (Datasourcetransactionmanager transactionmanager) {This.transactionmanager = TransactionManager; Public Map get (Integer id) throws Exception {String querysql = "SELECT * from customer where id =?"; Return Getjdbctemplate (). queryForMap (Querysql, new object[] {ID}); public void Insert (final Map customer) throws Exception {String seqsql = ' Select Customer_seql.nextval from D UAL "; String insertsql = "INSERT into customer (ID, code, name, status) VALUES (?,?,?,?)"; Transactiontemplate transactiontemplate = new Transactiontemplate (TransactionManager); Transactiontemplate.execute (New Transactioncallbackwithoutresult () { protected void Dointransactionwithoutresult (Transactionstatus status) {JdbcTemplate Jdbctempl ate = Getjdbctemplate (); int id = jdbctemplate.queryforint (seqsql); object[] params = new object[] {new Integer (ID), Customer.get ("code"), Customer.get ("name"), Map.get ("status")}; Jdbctemplate.update (Insertsql, params); }}} public void update (final MAP customer) throws Exception {//} public void Delete (intege R ID) throws Exception {String deletesql = "Delete from customer where id =?"; Transactiontemplate transactiontemplate = new Transactiontemplate (TransactionManager); Transactiontemplate.execute (New Transactioncallbackwithoutresult () {protected void Dointransactionwithoutresu Lt (transactionstatus status) {getjdbctemplate (). Update (Deletesql, new object[] {ID}); }}} public List findvalidcustomers () throws Exception {String querysql = "SELECT * from the customer where status = ' valid ' ORDER by code"; Return getjdbctemplate (). Query (Querysql, New Oraclecolumnmaprowmapper ()); }}
(RPM) Spring's programmatic transaction example