org.bdware.doip.audit.DOAuditRuleDB Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doip-audit-tool Show documentation
Show all versions of doip-audit-tool Show documentation
doip audit tool developed by bdware
package org.bdware.doip.audit;
import java.sql.*;
public class DOAuditRuleDB extends BasicDB {
public DOAuditRuleDB(String driverClass, String url, String user, String password) {
super(driverClass, url, user, password);
}
public boolean add(String tableName, DOAuditRule doAuditRule) throws SQLException {
Connection conn = getConn();
Statement statement = conn.createStatement();
String sql = "insert into ? values (?, ?)";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, formatTableName(tableName));
ps.setString(2, doAuditRule.doId);
ps.setInt(3, doAuditRule.type);
statement.executeUpdate(sql);
return true;
}
public boolean remove(String tableName, String doId) throws SQLException {
Connection conn = getConn();
Statement statement = conn.createStatement();
String sql = "delete from ? where ? = ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, formatTableName(tableName));
ps.setString(2, "doId");
ps.setString(3, doId);
statement.executeUpdate(sql);
return true;
}
public boolean modify(String tableName, DOAuditRule doAuditRule) throws SQLException {
Connection conn = getConn();
Statement statement = conn.createStatement();
String sql = "update ? set ? = ? where ? = ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, formatTableName(tableName));
ps.setString(2, "type");
ps.setInt(3, doAuditRule.type);
ps.setString(4, "doId");
ps.setString(5, doAuditRule.doId);
statement.executeUpdate(sql);
return true;
}
public int retrieve(String tableName, String doId) throws SQLException {
Connection conn = getConn();
Statement statement = conn.createStatement();
String sql = "select ? from ? where ? = ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, "type");
ps.setString(2, formatTableName(tableName));
ps.setString(3, "doId");
ps.setString(4, doId);
ResultSet resultSet = statement.executeQuery(sql);
return resultSet.getInt(1);
}
}