This utility fetches data from one schema which ia on different server.and inserts the entire data into other server with same schema.
import java.util.ArrayList; import java.util.List; import java.util.Vector; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; public class Example { public static void main(String[] args) throws InterruptedException { Connection connection = null; try { //String driverName ="oracle.jdbc.pool.OracleConnectionPoolDataSource"; String driverName ="oracle.jdbc.driver.OracleDriver"; Class.forName(driverName); String username = "catoracle"; String password = "catoracle"; String url="jdbc:oracle:thin:@157.227.102.89:1521:offshore"; connection = DriverManager.getConnection(url, username, password); ArrayList tableList = new ArrayList(); tableList.add("CATC_AGED_WRITEOFF_RULE"); tableList.add("CATC_APPLICATION"); tableList.add("CATC_CASE_ADVICE"); tableList.add("CATC_CASE_APRV_TEMP_DATA"); tableList.add("CATC_CASE_ASS_ERRTYPE_CASHLTR"); tableList.add("CATC_CASE_ASS_ERRTYPE_DLRAMT"); tableList.add("CATC_CASE_ASS_FIMP_FC"); tableList.add("CATC_CASE_CASH_LETTER"); //tableList.add("CATC_CASE_CHECK_INFO"); tableList.add("CATC_CASE_CORRESP"); tableList.add("CATC_CASE_CORRESPONDENCE"); //tableList.add("CATC_CASE_DATA"); //tableList.add("CATC_CASE_DEPOSIT_INFO"); //tableList.add("CATC_CASE_FINANCIAL_HIST"); //tableList.add("CATC_CASE_GL_DATA"); //tableList.add("CATC_CASE_NOTES"); //tableList.add("CATC_CASE_OPSACCTING"); //tableList.add("CATC_CASE_OTHER_INFO"); //tableList.add("CATC_CASE_SYSTEM_NOTES"); //tableList.add("CATC_CASE_TRANSFER_INFO"); //tableList.add("CATC_CASE_WORK_ITEM"); //tableList.add("CATC_CFS_TRANSACTION_DETAILS"); tableList.add("CATC_CORRESPONDENCE"); //tableList.add("CATC_CUSTOMER_REPORT_DATA"); tableList.add("CATC_DUPLICATE_RULE"); tableList.add("CATC_FED_PROD_CLT_MAPPING"); tableList.add("CATC_FED_SOURCEOFWORK"); tableList.add("CATC_HOLIDAY"); tableList.add("CATC_MARKET"); tableList.add("CATC_MKT_CONTROL_ACCOUNT"); tableList.add("CATC_MKT_DEPT"); tableList.add("CATC_MKT_DEPT_AGING_EXCEPTION"); tableList.add("CATC_MKT_DEPT_BANK"); tableList.add("CATC_MKT_DEPT_CAPTURE_SITE"); tableList.add("CATC_MKT_DEPT_CASHLETTER"); tableList.add("CATC_MKT_DEPT_ERRORTYPE"); tableList.add("CATC_MKT_DEPT_ERR_CORTYP_COR"); tableList.add("CATC_MKT_DEPT_ERR_CSHLTR_TYPE"); tableList.add("CATC_MKT_DEPT_GL"); tableList.add("CATC_MKT_DEPT_GL_CC"); tableList.add("CATC_MKT_DEPT_RETURNREASON"); tableList.add("CATC_MKT_DEPT_SITE"); tableList.add("CATC_MKT_DEPT_SOURCEOFERROR"); tableList.add("CATC_MKT_DEPT_SOURCEOFWORK"); tableList.add("CATC_MKT_FIMP"); tableList.add("CATC_OFFSET_RULE"); tableList.add("CATC_PEND_CASE_RULE"); tableList.add("CATC_PRIORITY_RULE"); tableList.add("CATC_PROFILE"); tableList.add("CATC_SMALL_WRITEOFF_RULE"); tableList.add("CATC_SPECIAL_HAND_INSTR"); tableList.add("CATC_SUB_ERRORTYPE"); tableList.add("CATC_USER"); tableList.add("CATC_USER_MKT_DEPT_SITE"); tableList.add("CATC_UTIL"); Statement st1=connection.createStatement(); ResultSet rs1=null; ResultSetMetaData rsmd=null; int count=0; for(int j=0;j<tableList.size();j++){ StringBuffer query = new StringBuffer(); query.append("SELECT *"); query.append("FROM "+tableList.get(j)); rs1=st1.executeQuery(query.toString()); rsmd=rs1.getMetaData(); count=rsmd.getColumnCount();String insertquery = "SELECT 'insert into "+tableList.get(j)+" values ('|| ''''|| "; for(int i=1;i<=count-1;i++) { insertquery = insertquery+rsmd.getColumnName(i)+ "||''''|| ',' || ''''||" ; } insertquery = insertquery+rsmd.getColumnName(count)+ "||''''||');'" ; insertquery = insertquery+" "+"from "+tableList.get(j)+";"; System.out.println(insertquery); insertquery=null; } } catch (ClassNotFoundException e) { System.out.println(e); } catch (SQLException e) { System.out.println(e); } } }