多个mysql数据库导入到单个mysql数据库中

public void run()throws Exception{
  File file = new File("d:" + File.separator + "contact.txt") ; 
  File file2 = new File("d:" + File.separator + "contact_field.txt") ; 
  Writer out = null ; 
  Writer out2 = null ; 
  out = new OutputStreamWriter(new FileOutputStream(file)) ; 
  out2 = new OutputStreamWriter(new FileOutputStream(file2)) ; 
  int id=1;
  int contact_field_id=1;
  
  for(int i=1;i<=50;i++){
   Connection conn = DriverManager.getConnection("jdbc:mysql://172.17.65.100:3306/pim"+i,"testuser","testpass");
   int offset = 0;
   int limit = 1000;
   List<Contact> list=findAllContact(conn,offset,limit);
   while(list.size() > 0){
   for(Contact c :list){
    List<ContactField> listf=findAllContactFieldByContactId(conn, c.getId());
    String sql="INSERT INTO contact (contact_id, created, updated, deleted, operation, subscriber_id, edit_by, is_star, version, create_version, home_phone," +
      " work_phone, home_email, work_email, display_name, mobile_phone, photo, client_id, device_id, name_firstChar, name_pinyin, is_private, contact_subscriber_id," +
      "modify_device_id, uuid, crc, adler, photo_length, namePhone_md5, checksum_version) " +
      "VALUES ("+id+",'"+c.getCreated()+"','"+c.getUpdated()+"',"+c.getDeleted()+","+c.getOperation()+","+c.getSubscriberId()+",'"+c.getEditBy()+"'," +
        ""+c.getIsStar()+","+c.getVersion()+","+c.getCreateVersion()+",'"+c.getHomePhone()+"','"+c.getWorkPhone()+"','"+c.getHomeEmail()+"','"+c.getWorkEmail()+"'," +
        "'"+c.getDisplayName()+"','"+c.getMobilePhone()+"','"+c.getPhoto()+"',"+c.getClientId()+",'"+c.getDeviceId()+"','"+c.getNameFirstChar()+"','"+c.getNamePinYin()+"'," +
        ""+c.getIsPrivate()+","+c.getContactSubscriberId()+",'"+c.getModifyDeviceId()+"','"+c.getUuid()+"','"+c.getCrc()+"','"+c.getAdler()+"',"+c.getPhotoLength()+"," +
        "'"+c.getNamePhonemd5()+"',"+c.getChecksumversion()+");";
        out.write(sql);
    out.write("\n");
    for(ContactField f : listf){
     f.setContactId(Long.valueOf(id));
     String sql2="INSERT INTO contact_field(field_id, contact_id, mime_type, flag, created, updated, create_version, version, operation, edit_by, data, deleted, client_id, device_id, deleted_contact, uuid)" +
       "VALUES("+contact_field_id+","+f.getContactId()+",'"+f.getMimeType()+"','"+f.getFlag()+"','"+f.getCreated()+"','"+f.getUpdated()+"',"+f.getCreateVersion()+"," +
       ""+f.getVersion()+","+f.getOperation()+",'"+f.getEditBy()+"','"+f.getData()+"',"+f.getDeleted()+","+f.getClientId()+",'"+f.getDeviceId()+"',"+f.getDeletedContact()+",'"+f.getUuid()+"');";
     out2.write(sql2);
     out2.write("\n");
     contact_field_id++;
    }
    id++;
   }
   offset+=limit;
   list=findAllContact(conn,offset,limit);
   
   }
   
  }
  out.close();
  out2.close();
  
 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值