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.

97 lines
2.7 KiB
Java

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 PGSQLEnc {
static final String DB_URL = "jdbc:postgressql://127.0.0.1:5432/miracle";
static final String USERNAME = "miracle";
static final String PASSWORD = "q!fvYOP^evn";
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("miraclefunding", "Agent!1700", "Agent!1700", "/home/inebsoft/javaapi/conf/dguard.conf");
conn = DriverManager.getConnection(DB_URL,USERNAME,PASSWORD);
conn.setAutoCommit(false);
System.out.println("- PostgreeSQL 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("- PostgreeSQL Connection Close");
}
}