All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.yydf.struts.jdbc.SqlTranction Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package com.github.yydf.struts.jdbc;

import java.sql.Connection;
import java.sql.SQLException;

import com.github.yydf.struts.util.JdbcUtils;

/**
 * 事务处理
 * 
 * @author YYDF 2018-12-06
 * @since 1.7
 */
public class SqlTranction {
	private Connection connection;

	public SqlTranction(Connection conn) throws SQLException {
		conn.setAutoCommit(false);
		this.connection = conn;
	}

	public void commit() {
		try {
			connection.commit();
			// logger.debug("Tranction commit");
		} catch (SQLException e) {
			e.printStackTrace();
			// logger.error("Tranction commit faild", e);
		}
	}

	public void rollback(Exception e) {
		try {
			// logger.error("Execute faild", e);
			connection.rollback();
			// logger.debug("Tranction rollback");
		} catch (SQLException ee) {
			e.printStackTrace();
			// logger.error("Tranction rollback faild", ee);
		}
	}

	public Connection Connection() {
		return this.connection;
	}

	public void close() {
		JdbcUtils.closeTranction(connection);
		// logger.debug("Tranction closed");
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy