java 同步資料

來源:互聯網
上載者:User

標籤:

  1 public void Sync_data(){  2   3     Connection ocd_query_erp = null;  4         Connection o_to_portal=null;  5   6         String form_form_ocd_configuration="select org_vdc from OCD_Test";//從mysql拿對應到資源集區的資料  7         String form_erp_ocd_sql="select org_cid,vms,provider_vdc,org_vdc,cpu,ram,storage,storage_plus from OCD_Test";//從erp拿資料   8         String portal_ocd_Insert_sql="insert into OCD_Test(org_cid,vms,provider_vdc,org_vdc,cpu,ram,storage,storage_plus) values(?,?,?,?,?,?,?,?)";  9         String portal_ocd_Update_sql="update OCD_Test set org_cid=?,vms=?,provider_vdc=?,cpu=?,ram=?,storage=?,storage_plus=? where org_vdc =?"; 10          11     List ocdIdList = new ArrayList(); 12  13             PreparedStatement o_query_erp = null; 14         PreparedStatement o_update_ocd = null; 15         PreparedStatement o_insert_ocd = null; 16  17 //定義參數 18     String org_cid=""; 19         int vms=0; 20         String provider_vdc=""; 21         String org_vdc=""; 22         String cpu=""; 23         String ram=""; 24         int storage=0; 25         int storage_plus; 26  27 //先擷取到對應的資料庫 28         ocd_query_erp= this.getConnection(datasource_from[0].getDrv(), datasource_from[0].getUri(), datasource_from[0].getUid(), datasource_from[0].getPwd()); 29             o_to_portal = this.getConnection(datasource_from[0].getDrv(), datasource_from[0].getUri(), datasource_from[0].getUid(), datasource_from[0].getPwd());; 30  31 //先行編譯sql語句 32     o_query_erp=ocd_query_erp.prepareStatement(form_erp_ocd_sql); 33             o_update_ocd=to_portal.prepareStatement(portal_ocd_Update_sql); 34             o_insert_ocd=to_portal.prepareStatement(portal_ocd_Insert_sql); 35      36         Statement o_to_portal_ = to_portal.createStatement(); 37             ResultSet ocd_configuration = o_to_portal_ 38                     .executeQuery(form_form_ocd_configuration); 39             while (ocd_configuration.next()) { 40                 String tmp = ocd_configuration.getString(1); 41                 ocdIdList.add(tmp); 42             } 43             ocd_configuration.close(); 44             o_to_portal_.close(); 45  46  47 //載入資料 48             rs_from = o_query_erp.executeQuery(); 49             if (rs_from != null) { 50                 while (rs_from.next()) { 51                         // select 52                         // org_cid,vms,provider_vdc,org_vdc,cpu,ram,storage,storage_plus 53                         // from OCD_Test 54                         org_cid =    UI18n.getUnicode(rs_from.getString(1), "gbk"); 55                         vms = rs_from.getInt(2); 56                         provider_vdc =    UI18n.getUnicode(rs_from.getString(3), "gbk"); 57                         org_vdc =     UI18n.getUnicode(rs_from.getString(4), "gbk"); 58                     //    org_vdc =     rs_from.getString(4), "gbk"); 59                         System.out.println(rs_from.getString(4)); 60                         System.out.println(org_vdc); 61                         cpu = rs_from.getString(5); 62                         ram = rs_from.getString(6); 63                         storage = rs_from.getInt(7); 64                         storage_plus = rs_from.getInt(8); 65  66                         if (!ocdIdList.contains(org_vdc)) { 67         //    insert into OCD_Test(org_cid,vms,provider_vdc,org_vdc,cpu,ram,storage,storage_plus) values(?,?,?,?,?,?,?,?)"; 68                             o_insert_ocd.setString(1, org_cid); 69                             o_insert_ocd.setInt(2, vms); 70                             o_insert_ocd.setString(3, provider_vdc); 71                             o_insert_ocd.setString(4, org_vdc); 72                             o_insert_ocd.setString(5, cpu); 73                             o_insert_ocd.setString(6, ram); 74                             o_insert_ocd.setInt(7,storage); 75                             o_insert_ocd.setInt(8, storage_plus); 76                          77                             int result = o_insert_ocd.executeUpdate(); 78                             o_insert_ocd.clearParameters(); 79                             count_insert += result; 80                             log.info(count_insert + "  INERT OCD_Test: org_vdc=" + org_vdc + " OK!"); 81                         } else { 82                              83     //update OCD_Test set ,org_cid=?,vms=?,provider_vdc=?,cpu=?,ram=?,storage=?,storage_plus=? where org_vdc =?"; 84                             o_update_ocd.setString(1,org_cid ); 85                             o_update_ocd.setInt(2, vms); 86                             o_update_ocd.setString(3, provider_vdc); 87                             o_update_ocd.setString(4, cpu); 88                             o_update_ocd.setString(5, ram); 89                             o_update_ocd.setInt(6, storage); 90                             o_update_ocd.setInt(7, storage_plus); 91                             o_update_ocd.setString(8, org_vdc); 92                               93                             System.out.println(o_update_ocd.toString()); 94                             count_update += o_update_ocd.executeUpdate(); 95                             log.info("UPDATE org_vdc=" + org_vdc + " OK!"); 96                              97                         } 98                 } 99             }100 101 102 }103 104 

 

java 同步資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.