Considerations for Oracle rollback

Source: Internet
Author: User


When you roll back to fisrt (), note that you need to move the cursor to the first line before using previous (); package com. trs. util; www.2cto.com import java. util. calendar; import java. util. date; import java. util. properties; import java. SQL. connection; import java. SQL. resultSet; import java. text. simpleDateFormat; import org. apache. log4j. logger; import com. trs. client. TRSConnection; import com. trs. client. TRSResultSet; import com. trs. dao. oracleDao; import com. trs. dao. tr SDao; public class checkTest {private static Logger CheckTRSLogger = Logger. getLogger ("CheckTRSLogger"); public static void check () {Date dateSta = null; // time period start Date dateEnd = null; // time period end Date dateComp = null; // The total time ends with Calendar calSta = Calendar. getInstance (); Calendar calEnd = Calendar. getInstance (); Calendar calComp = Calendar. getInstance (); String calStaString = ""; www.2cto.com String calEndStrin G = ""; TRSConnection trsCon = null; TRSResultSet trsRs = null; Connection oraCon = null; ResultSet limit lers = null; String table = ""; // The Name Of The table retrieved in oracle String tableTem = ""; // temporary table name in oracle String tableRecord = ""; // String column_oracle1 = ""; // String column_oracle2 = ""; // String host = ""; // trs database ip String port = ""; // trs database port String username = ""; // trs database username Strin G password = ""; // trs database password String library = ""; // trs Database Retrieval Database Name String column_trs1 = ""; // retrieve the field name String column_trs2 = "" In the trs database; // The key field name int trsNum = 0 in the trs database; // The number of TRS records int oracleNum = 0; // Number of Oracle records try {DBUtil. loadProperties ("oracleconfig. properties ");} catch (Exception e2) {www.2cto.com e2.printStackTrace (); CheckTRSLogger. error (e2.getMessage ();} table = DBUtil. getConfigInfo ("table"); tableT Em = DBUtil. getConfigInfo ("tableTem"); tableRecord = DBUtil. getConfigInfo ("tableRecord"); column_oracle1 = DBUtil. getConfigInfo ("column_oracle1"); column_oracle2 = DBUtil. getConfigInfo ("column_oracle2"); try {DBUtil. loadProperties ("trsconfig. properties ");} catch (Exception e2) {e2.printStackTrace (); CheckTRSLogger. error (e2.getMessage ();} host = DBUtil. getConfigInfo ("host"); // trs database ip port = D BUtil. getConfigInfo ("port"); // trs database port username = DBUtil. getConfigInfo ("username"); // trs database username password = DBUtil. getConfigInfo ("password"); // trs Database password library = DBUtil. getConfigInfo ("library"); // retrieves the database name column_trs1 = DBUtil in the trs database. getConfigInfo ("column1"); // retrieves the field name column_trs2 = DBUtil in the trs database. getConfigInfo ("column2"); // retrieve key field names in the trs database try {DBUtil. loadProperties ("timeLimits. properties ");} catch (Exce Ption e2) {e2.printStackTrace (); CheckTRSLogger. error (e2.getMessage ();} String dateStaString = DBUtil. getConfigInfo ("DateSta"); String dateEndString = DBUtil. getConfigInfo ("dateEnd"); String dateCompString = DBUtil. getConfigInfo ("dateComp"); String dataFormate = "yyyy. MM. dd HH: mm: ss "; www.2cto.com SimpleDateFormat dateformat = new SimpleDateFormat (dataFormate); try {dateSta = dateformat. parse (d AteStaString); dateEnd = dateformat. parse (dateEndString); dateComp = dateformat. parse (dateCompString); calSta. setTime (dateSta); calEnd. setTime (dateEnd); calComp. setTime (dateComp);} catch (Exception e) {e. printStackTrace (); CheckTRSLogger. error (e. getMessage ();} int dayNum = (calEnd. get (Calendar. YEAR)-calSta. get (Calendar. YEAR) * 365 + calEnd. get (Calendar. DAY_OF_YEAR)-calSta. get (Calendar. DAY_OF_YEAR ); String calCompString = dateformat. format (calComp. getTime (); // The time is less than the end time to execute the Comparison Program while (calEnd. before (calComp) {calStaString = dateformat. format (calSta. getTime (); calEndString = dateformat. format (calEnd. getTime (); try {trsCon = trsDao. getTRSConnection (host, port, username, password); trsRs = trsDao. readTRS (trsCon, library, column_trs1, calStaString, calEndString); trsNum = (int) trsRs. getRecordCoun T (); CheckTRSLogger.info ("this time period" + calStaString + "-----" + calEndString + "TRS record volume" + trsNum); oraCon = oracleDao. getOracleConnection (); login lers = oracleDao. readOracle (oraCon, table, column_oracle1, column_oracle2, calStaString, calendar string); extends lers. last (); www.2cto.com oracleNum = policlers. getRow (); extends lers. first (); then lers. previous (); if (oracleNum> trsNum) {if (trsNum> 0) {for (int I = 0; I <trsNum; I ++) {TrsRs. moveTo (0, I); String columnValue = trsRs. getString (column_trs2); oracleDao. insertOracle (oraCon, tableTem, column_oracle1, columnValue);} try {trsRs. close (); trsCon. close ();} catch (Exception e) {e. printStackTrace (); CheckTRSLogger. error (e. getMessage ();} while (extends lers. next () {String temColumnValue = extends lers. getString (column_oracle1); if (! OracleDao. isExt (oraCon, tableTem, column_oracle1, temColumnValue) {oracleDao. insertOracle (oraCon, tableRecord, column_oracle1, temColumnValue) ;}} oracleDao. deleteOracle (oraCon, tableTem);} else {while (batch lers. next () {String temColumnValue1 = extends lers. getString (column_oracle1); oracleDao. insertOracle (oraCon, tableRecord, column_oracle1, temColumnValue1);} www.2cto.com }}catch (Exception e) {e. printStackTrace (); CheckTRSLogger. error (e. getMessage ();} finally {try {receivlers. close ();} catch (Exception e) {e. printStackTrace (); CheckTRSLogger. error (e. getMessage ();} try {oraCon. close ();} catch (Exception e) {e. printStackTrace (); CheckTRSLogger. error (e. getMessage ();} try {trsRs. close ();} catch (Exception e) {e. printStackTrace (); CheckTRSLogger. error (e. getMessage ();} try {trsCon. close ();} catch (Exception e) {e. printStackTrace (); CheckTRSLogger. error (e. getMessage () ;}} www.2cto.com CheckTRSLogger.info ("time period compared:" + calStaString + "----------" + Calendar string); calSta = (Calendar) calEnd. clone (); calEnd. add (Calendar. DAY_OF_YEAR, dayNum) ;}} by ygsilence

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.