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
时间: 2024-11-05 18:31:02