导入文件到数据库

  1. #include <time.h>
  2. #include <signal.h>
  3. #include "seetime.h"
  4. #include "writeoff_inc.h"
  5. /*
  6.     DB_USER_FEE_DETAIL db_user_fee_detail;
  7.     Connection* amsConn;
  8.     char sql[1024];
  9.     IND_USER_FEE_DETAIL_BY_INSPRODID ind_user_fee_detail_by_insprodid;
  10. long InitUserInfo()
  11. {
  12.   long j = 0;
  13.   strcpy(g_struGlobalParam.szRegion, "a");
  14.   sprintf(sql, 
  15.       " SELECT PRODUCT_INSTANCE_ID, 0 HIS_AMOUNT, 0 LAST_AMOUNT, 0 HIS_BALANCE, 0 CUR_AMOUNT, "
  16.       "        0 CUR_BALANCE, 0 INVALID_BALANCE, 0 CALL_FEE, 0 RENT_FEE, 0 FAVOR_FEE, "
  17.       "        0 FAVOR_PFEE, 0 PAYMENT_FEE, 0 LATE_FEE, 0 APPORTION_FEE, 0 PRESENT_FEE,"
  18.       "        0 DELMON_FEE, TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS') OPT_DATE "
  19.       "   FROM INS_PROD_%s "
  20.       "  WHERE STATE NOT IN('C', 'D', 'E') ", g_struGlobalParam.szRegion);
  21. //  sprintf(sql, "SELECT PRODUCT_INSTANCE_ID FROM INS_PROD_A WHERE 1 = 1");
  22.   g_cLogFile.Info(0, "加载用户资料,SQL=[%s]", sql);
  23.   j = db_user_fee_detail.LoadByRecord(*amsConn, sql);
  24.   if (j <= 0)
  25.   {
  26.     g_cLogFile.Error(0, "加载用户资料到内存失败");
  27.     cout << amsConn->GetMsg() << endl;
  28.     return -1;
  29.   }
  30.   g_cLogFile.Info(0, "装载用户资料成功,共计[%d]条", db_user_fee_detail.GetNodeNumber());
  31. //  CRecords c_record(*amsConn, 1);
  32. //  c_record.Query(sql);
  33. //  for (int i = 0; i < 10; i++)
  34. //  {
  35. //    cout << c_record.Field(0).Float() << endl;
  36. //    c_record.Next();
  37. //  }
  38.   return j;
  39. }
  40. long OutputFeeDetail()
  41. {
  42.   long j = 0;
  43.   int nTotalCounts = 0;
  44.   T_USER_FEE_DETAIL tUserFeeDetail;
  45.   T_LIST<STRU_USER_FEE_DETAIL> *plistUserFeeDetail = NULL;
  46.   tUserFeeDetail.SetConn(*amsConn);
  47.   tUserFeeDetail.SetBatSize(MAX_BATCH_SIZE);
  48.   tUserFeeDetail.SetTableName("aa");
  49.   plistUserFeeDetail = db_user_fee_detail.GetList();
  50.   plistUserFeeDetail->GoHead();
  51.   while (j >= 0 && plistUserFeeDetail->Position())
  52.   {
  53.     nTotalCounts ++;
  54.     db_user_fee_detail.ConvToTable(tUserFeeDetail, plistUserFeeDetail->Current());
  55.     j = tUserFeeDetail.Insert();
  56.     if (j <= 0)
  57.     {
  58.       g_cLogFile.Error(0, "帐单变化表[%s]插入失败,失败原因:[%s]",
  59.           tUserFeeDetail.Name(), amsConn->GetMsg());
  60.       j = -1;
  61.       break;
  62.     }
  63.     plistUserFeeDetail->Next();  
  64.     if (!plistUserFeeDetail->Position())
  65.     {
  66.       g_cLogFile.Info(0, "已生成[%d]条帐单变化记录", nTotalCounts);
  67.     }
  68.     if (!plistUserFeeDetail->Position())
  69.     {
  70.       j = tUserFeeDetail.Flush();
  71.       if (j <= 0)
  72.       {
  73.         j = -1;
  74.         g_cLogFile.Error(0, "帐单变化表[%s]FLUSH失败,失败原因:[%s]", 
  75.             tUserFeeDetail.Name(), amsConn->GetMsg());
  76.       }
  77.       if (j >= 0)
  78.       {
  79.         amsConn->Commit();
  80.       }
  81.       else
  82.       {
  83.         amsConn->Rollback();
  84.       }
  85.     }
  86.   }
  87.   return j;
  88. }
  89. int main()
  90. {
  91.     Settime();
  92.     long j = Login("ORACLE");
  93.     if (j <= 0)
  94.     {
  95.         cout << "数据库连接失败" << endl;
  96.         return -1;
  97.     }
  98.     DbFactory.Initial();
  99.     DbFactory.GetConnection("ams", "1", amsConn);
  100.     
  101.     db_user_fee_detail.SetBatchSize(MAX_BATCH_SIZE);
  102.     db_user_fee_detail.AddIndex(&ind_user_fee_detail_by_insprodid);
  103.     InitUserInfo();
  104. //  OutputFeeDetail();
  105.     STRU_USER_FEE_DETAIL* stru;
  106.     ind_user_fee_detail_by_insprodid.Query(3804338, stru);
  107.     cout << stru->PRODUCT_INSTANCE_ID << endl;
  108.     cout << stru->OPT_DATE << endl;
  109.     CRecords record(*amsConn, 1);
  110.     char str[256];
  111.     strcpy(str, "select * from student");
  112.     j = record.Query(str);
  113.     while (j > 0)
  114.     {
  115.         cout << record.Field("SNO").Char() << " ";
  116.         cout << record.Field("SNAME").Char() << endl;
  117.         j = record.Next();
  118.     }
  119.     DbFactory.FreeConnection(amsConn);
  120.     Logout();
  121.     cout << Gettime() << endl;
  122.     return 0;
  123. }*/
  124. /*
  125. //表类的应用
  126. int main()
  127. {
  128.     long j = Login("ORACLE");
  129.     if (j <= 0)
  130.     {
  131.         cout << "Login failed" << endl;
  132.         return 1;
  133.     }
  134.     Connection* amsConn = NULL;
  135.     DbFactory.Initial();
  136.     DbFactory.GetConnection("ams", "1", amsConn);
  137. //  CRecords crecord(*amsConn, 1);
  138. //
  139. //  char sql[256];
  140. //  sprintf(sql, "insert into cc values('1','123','20081010121222')");
  141. //  j = crecord.Query(sql);
  142. //  if (j <= 0)
  143. //  {
  144. //      cout << "Query lost" << endl;
  145. //      cout << amsConn->GetMsg() << endl;
  146. //      return 1;
  147. //  }
  148. //
  149. //  amsConn->Commit();
  150.     T_SMS_CUR_BALANCE table_a(*amsConn, 1);
  151.     table_a.SetTableName("cc");
  152.     table_a.ACCT_ID = 1;
  153.     table_a.BALANCE = 23;
  154.     table_a.OPT_DATE = "2008091012";
  155.     j = table_a.Insert();
  156.     if (j <= 0)
  157.     {
  158.         cout << amsConn->GetMsg() << endl;
  159.         return 1;
  160.     }
  161.     amsConn->Commit();
  162.     Logout();
  163.     return 0;
  164. }*/
  165. int main()
  166. {
  167.     Settime();
  168.     long j = Login("ORACLE");
  169.     if (j <= 0 )
  170.     {
  171.         cout << "Connect lost" << endl;
  172.         return 1;
  173.     }
  174.     Connection* amsConn = NULL;
  175.     DbFactory.Initial();
  176.     j = DbFactory.GetConnection("ams""1", amsConn);
  177.     if (j <= 0)
  178.     {
  179.         cout << "Db lost" << endl;
  180.         return 1;
  181.     }
  182.     T_ACCT_BALANCE table_a(*amsConn, 1);
  183.     table_a.SetTableName("cc");
  184.     
  185.     CFileReader cread("F://test.txt"","" " );
  186.     j = cread.Open();
  187.     int i = 0;
  188.     while (j > 0)
  189.     {
  190.         table_a.ACCT_BALANCE_ID = (long int)_atoi64(cread.GetField(4));
  191.         table_a.ACCT_ID = (long int)_atoi64(cread.GetField(5));
  192.         table_a.PAYMENT_ID = 1;
  193.         table_a.EFF_DATE = cread.GetField(6);
  194.         table_a.EXP_DATE = cread.GetField(7);
  195.         table_a.OPT_DATE = cread.GetField(8);
  196.         table_a.Insert();
  197.         j = cread.Next();
  198.         i++;
  199.     }
  200.     j = amsConn->Commit();
  201.     if (j <= 0)
  202.     {
  203.         cout << amsConn->GetMsg() << endl;
  204.         return 1;
  205.     }
  206.     cout << "OK" << endl;
  207.     cout << i << endl;
  208.     cread.Close();
  209.     DbFactory.FreeConnection(amsConn);
  210.     cout << Gettime() << endl;
  211.     return 0;
  212. }

 =========

使用sqlldr 是个不错的方法

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值