// Deleting all records from imal_account_temp
String tempAccountDelete = "delete from imal_account_temp";
statement = connection.prepareStatement(tempAccountDelete);
statement.executeUpdate();
// Inserting records from imal_account into imal_account_temp
String tempAccount = "insert into imal_account_temp(ROWNUMBER, BRANCHCODE, CY_CODE, GL_CODE, CIF_SUB_NO) " +
" select ROWNUMBER, BRANCHCODE, CY_CODE, GL_CODE, CIF_SUB_NO from imal_account ";
//System.out.println(""+tempAccount);
statement = connection.prepareStatement(tempAccount);
statement.executeUpdate();
connection.commit();
String accountForUpdateQuery = "SELECT ROWNUMBER, brm_code, BRANCHCODE, CY_CODE, GL_CODE, " +
" CIF_SUB_NO, SL_NO, ACCT_BASC, ACCT_SFIX, " +
" NOMN_ACCT_NUMB, NOMN_ACCT_SFIX, FUND_ACCT_NUMB, FUND_ACCT_SFIX" +
" from imal_account ";
statement = connection.prepareStatement(accountForUpdateQuery);
result = statement.executeQuery();
String tempQuery="";
ResultSet resultTemp=null;
while(result.next()) {
PreparedStatement statementCurrent= null;
//Updating GL_CODE now
accountUpdateQuery = "update imal_account a " +
" set a.GL_CODE = ( select IMAL_ACCOUNT from imal_account_map " +
" where ACCT_TYPE = a.ACCT_TYPE and rownum = 1) " +
" where a.ROWNUMBER = " + result.getLong("ROWNUMBER") ;
//DBManager.logMessage("3>> "+accountUpdateQuery);
statementCurrent = connection.prepareStatement(accountUpdateQuery);
statementCurrent.executeUpdate();
statementCurrent.close();
//Updating PFT_GL now
accountUpdateQuery = "update imal_account a " +
" set a.PFT_GL = ( select IMAL_ACCOUNT from imal_account_map " +
" where ACCT_TYPE = (select acct_type " +
" from pls.md " +
" where BRAN_CODE = " + result.getLong("BRANCHCODE") +
" and ACCT_BASC = " + result.getLong("NOMN_ACCT_NUMB") +
" and ACCT_SFIX = " + result.getLong("NOMN_ACCT_SFIX") +
" ) " +
" ) " +
" where a.ROWNUMBER = " + result.getLong("ROWNUMBER") ;
//DBManager.logMessage("4>> "+accountUpdateQuery);
statementCurrent = connection.prepareStatement(accountUpdateQuery);
statementCurrent.executeUpdate();
statementCurrent.close();
//Updating RENEW_GL now
accountUpdateQuery = "update imal_account a " +
" set a.RENEW_GL = ( select IMAL_ACCOUNT from imal_account_map " +
" where ACCT_TYPE = (select acct_type " +
" from pls.md " +
" where BRAN_CODE = " + result.getLong("BRANCHCODE") +
" and ACCT_BASC = " + result.getLong("FUND_ACCT_NUMB") +
" and ACCT_SFIX = " + result.getLong("FUND_ACCT_SFIX") +
" ) " +
" ) " +
" where a.ROWNUMBER = " + result.getLong("ROWNUMBER") ;
//DBManager.logMessage("5>> "+accountUpdateQuery);
statementCurrent = connection.prepareStatement(accountUpdateQuery);
statementCurrent.executeUpdate();
statementCurrent.close();
//Checking if this record already exist in imal_account_temp table
tempQuery = "select ROWNUMBER, BRANCHCODE, CY_CODE, GL_CODE, CIF_SUB_NO from imal_account_temp " +
" where BRANCHCODE = " + result.getLong("BRANCHCODE") +
" and CY_CODE = " + result.getLong("CY_CODE") +
" and GL_CODE = " + result.getLong("GL_CODE") +
" and CIF_SUB_NO = " + result.getLong("CIF_SUB_NO") +
" and SL_NO is null ";
statementCurrent = connection.prepareStatement(tempQuery);
resultTemp = statementCurrent.executeQuery();
//if record exists then
int counter = 0;
while(resultTemp.next()) {
PreparedStatement statementTemp= null;
counter = counter + 1;
tempQuery = "update imal_account_temp set SL_NO = " + counter +
" where ROWNUMBER = " + resultTemp.getLong("ROWNUMBER") +
" and BRANCHCODE = " + resultTemp.getLong("BRANCHCODE") +
" and CY_CODE = " + resultTemp.getLong("CY_CODE") +
" and GL_CODE = " + resultTemp.getLong("GL_CODE") +
" and CIF_SUB_NO = " + resultTemp.getLong("CIF_SUB_NO") ;
statementTemp = connection.prepareStatement(tempQuery);
statementTemp.executeUpdate();
statementTemp.close();
}
statementCurrent.close();
}
connection.commit();
// Updating SL_NO in imal_account table from imal_account_temp
accountUpdateQuery = "update imal_account a " +
" set a.SL_NO = (select b.SL_NO " +
" from imal_account_temp b " +
" where a.ROWNUMBER = b.ROWNUMBER) " ;
//System.out.println(""+accountUpdateQuery);
statement = connection.prepareStatement(accountUpdateQuery);
statement.executeUpdate();
statement.close();
connection.commit();
|