com.github.yydf.struts.jdbc.SqlTranction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of struts Show documentation
Show all versions of struts Show documentation
A simple, light Java WEB + ORM framework.
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");
}
}