时间:2021-07-01 10:21:17 帮助过:19人阅读
JDBC code:
package com.pp.jdbc; import java.sql.Connection; import java.sql.PreparedStatement; import org.junit.Test; import com.pp.util.JdbcUtil; public class TransactionDemo { @Test public void test1() { Connection connection = null; PreparedStatement pstatement = null; try { connection = JdbcUtil.getConnection(); // start transaction connection.setAutoCommit(false); pstatement = connection .prepareStatement("UPDATE accout SET money=money-100 WHERE name=‘aa‘"); pstatement.executeUpdate(); pstatement = connection .prepareStatement("UPDATE accout SET money=money-100 WHERE name=‘aa‘"); pstatement.executeUpdate(); // commit connection.commit(); } catch (Exception e) { e.printStackTrace(); } finally { } } }
JDBC - Transaction
标签:tco demo null opera val print on() exception bsp