You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
2.8 KiB
Java
99 lines
2.8 KiB
Java
8 months ago
|
import com.Ineb.Dguard.*;
|
||
|
import com.Ineb.Exception.DguardLoginException;
|
||
|
import com.Ineb.Exception.DguardNetworkException;
|
||
|
import com.Ineb.Exception.DGuardPropertyException;
|
||
|
|
||
|
import java.io.*;
|
||
|
import java.sql.*;
|
||
|
|
||
|
public class MySQLEnc {
|
||
|
|
||
|
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
|
||
|
static final String DB_URL = "jdbc:mysql://192.168.100.211:3306/testdb";
|
||
|
|
||
|
static final String USERNAME = "ineb";
|
||
|
static final String PASSWORD = "ineb1234";
|
||
|
|
||
|
public static void main(String[] args) {
|
||
|
DguardManager dm = null;
|
||
|
|
||
|
Connection conn = null;
|
||
|
PreparedStatement pstmt = null;
|
||
|
PreparedStatement updatePstmt = null;
|
||
|
ResultSet rset=null;
|
||
|
|
||
|
try{
|
||
|
dm = DguardManager.Init("bidfunding", "Agent!1700", "Agent!1700", "/home/dguard/javaapi/conf/dguard.conf");
|
||
|
|
||
|
Class.forName(JDBC_DRIVER);
|
||
|
conn = DriverManager.getConnection(DB_URL,USERNAME,PASSWORD);
|
||
|
conn.setAutoCommit(false);
|
||
|
System.out.println("- MySQL Connection");
|
||
|
|
||
|
String selectSql = "SELECT seq, data FROM tbl01";
|
||
|
pstmt = conn.prepareStatement(selectSql.toString());
|
||
|
rset = pstmt.executeQuery();
|
||
|
|
||
|
String updateSql = "UPDATE tbl01 SET data = ? WHERE seq = ?";
|
||
|
updatePstmt = conn.prepareStatement(updateSql.toString());
|
||
|
|
||
|
int commitCnt = 0;
|
||
|
|
||
|
while(rset.next()){
|
||
|
int seq = rset.getInt("SEQ");
|
||
|
String data01 = rset.getString("data");
|
||
|
|
||
|
String encdata01 = dm.Encrypt("TBL", "ENC", data01);
|
||
|
|
||
|
System.out.print("SEQ : " + seq + "\n");
|
||
|
System.out.print("DATA : " + data01 + "\n");
|
||
|
System.out.print("ENC : " + encdata01 + "\n");
|
||
|
|
||
|
updatePstmt.setString(1, encdata01);
|
||
|
updatePstmt.setInt(2, seq);
|
||
|
|
||
|
updatePstmt.addBatch();
|
||
|
updatePstmt.clearParameters();
|
||
|
|
||
|
if ( commitCnt > 0 && commitCnt % 1000 == 0 ) {
|
||
|
updatePstmt.executeBatch();
|
||
|
updatePstmt.clearBatch();
|
||
|
conn.commit();
|
||
|
|
||
|
System.out.println(commitCnt + ", " + data01 + ", " + encdata01);
|
||
|
}
|
||
|
|
||
|
commitCnt++;
|
||
|
}
|
||
|
|
||
|
updatePstmt.executeBatch();
|
||
|
conn.commit();
|
||
|
conn.setAutoCommit(true);
|
||
|
|
||
|
System.out.println("Commit count : " + commitCnt);
|
||
|
|
||
|
rset.close();
|
||
|
updatePstmt.close();
|
||
|
pstmt.close();
|
||
|
conn.close();
|
||
|
}catch(SQLException se1){
|
||
|
se1.printStackTrace();
|
||
|
}catch(Exception ex){
|
||
|
ex.printStackTrace();
|
||
|
}finally{
|
||
|
try{
|
||
|
if(pstmt!=null)
|
||
|
pstmt.close();
|
||
|
}catch(SQLException se2){
|
||
|
}
|
||
|
try{
|
||
|
if(conn!=null)
|
||
|
conn.close();
|
||
|
}catch(SQLException se){
|
||
|
se.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
System.out.println("- MySQL Connection Close");
|
||
|
}
|
||
|
}
|