| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 749 人关注过本帖
标题:如何批量把A库的数据插入到B库中
只看楼主 加入收藏
ccqz
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2022-5-8
收藏
 问题点数:0 回复次数:0 
如何批量把A库的数据插入到B库中
把oracle数据库中的A库的CT_CUS_PAYITEMSCATE_INIT表同步到B库中的CT_CUS_PAYITEMSCATE_INIT,想通过insert into select方式实现
按照下面的代码执行后,提示
Exception                                 Traceback (most recent call last)
File OraclePreparedStatementWrapper.java:221, in oracle.jdbc.driver.OraclePreparedStatementWrapper.setObject()
File OraclePreparedStatement.java:8370, in oracle.jdbc.driver.OraclePreparedStatement.setObject()
File OraclePreparedStatement.java:8395, in oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal()
File OraclePreparedStatement.java:7639, in oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal()
File OraclePreparedStatement.java:7708, in oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical()
File OraclePreparedStatement.java:4889, in oracle.jdbc.driver.OraclePreparedStatement.setStringInternal()
Exception: Java Exception
The above exception was the direct cause of the following exception:
java.sql.SQLException                     Traceback (most recent call last)
Input In [35], in <cell line: 29>()
     33     sqlInsert="insert into"+' '+"CT_CUS_PAYITEMSCATE_INIT"+"(FREGIONCODE, FCATEGORYNUMBER, FCATEGORYNAME, FCATEGORYSUBCODE, FCATEGORYSUBNAME, FPAYITEMNUMBER, FPAYITEMNAME, FPAYITETYPE, FCATEGORYID, FCATEGORYSUBID)"
     34     sqlInsert=sqlInsert+" Values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);"
---> 35     cursTo.execute(sqlInsert,value)
     36     ()
     37 #cursTo.execute(sqlStr)
     38 #resultTo = cursFrom.fetchall()

File D:\Programs\Python\Python\lib\site-packages\jaydebeapi\__init__.py:532, in Cursor.execute(self, operation, parameters)
    530 self._close_last()
    531 self._prep = self._connection.jconn.prepareStatement(operation)
--> 532 self._set_stmt_parms(self._prep, parameters)
    533 try:
    534     is_rs = self._prep.execute()

File D:\Programs\Python\Python\lib\site-packages\jaydebeapi\__init__.py:523, in Cursor._set_stmt_parms(self, prep_stmt, parameters)
    520 def _set_stmt_parms(self, prep_stmt, parameters):
    521     for i in range(len(parameters)):
    522         # print (i, parameters[i], type(parameters[i]))
--> 523         prep_stmt.setObject(i + 1, parameters[i])
java.sql.SQLException: java.sql.SQLException: 无效的列索引

我把原结果集中的数据和通过循环产生的数据都比对了,列的个数一致。下面是其中的一条数据
('3202', '3202-02', '种植治疗', '3202-02-003', '种植修复基台', '3202-02-N0020', '安卓健复合基台', 0, '3mh++7UdYAXgU2kAAAqkqvaZ/iw=', '3mh++7UjYAXgU2kAAAqkqkpSiHQ=')

代码如下:
import sys
import os
import jaydebeapi

url = 'jdbc:oracle:thin:@8.142.180.78:1521:MAEASDB'
driver = 'oracle.jdbc.driver.OracleDriver'
userFrom = 'test'
passwordFrom = 'test'
jarFile = 'D:/Tools/JDBC/ojdbc8.jar'
connFrom = jaydebeapi.connect(jclassname=driver,
                          url=url,
                          driver_args=[userFrom, passwordFrom],
                          jars=jarFile)
cursFrom = connFrom.cursor()
userTo = 'MAEAS'
passwordTo = 'MAEAS'
jarFile = 'D:/Tools/JDBC/ojdbc8.jar'
connTo = jaydebeapi.connect(jclassname=driver,
                          url=url,
                          driver_args=[userTo, passwordTo],
                          jars=jarFile)
sqlStr = 'select FREGIONCODE, FCATEGORYNUMBER, FCATEGORYNAME, FCATEGORYSUBCODE, FCATEGORYSUBNAME, FPAYITEMNUMBER, FPAYITEMNAME, FPAYITETYPE, FCATEGORYID, FCATEGORYSUBID from CT_CUS_PAYITEMSCATE_INIT'
cursFrom.execute(sqlStr)
resultFrom = cursFrom.fetchall()
#cursTo.execute(sqlStr)
#result = cursFrom.fetchall()
#print(resultFrom)
value=()
for i in range(len(resultFrom)):
    cursTo = connTo.cursor()
    value=(resultFrom[i])
   # print(value)
    sqlInsert="insert into"+' '+"CT_CUS_PAYITEMSCATE_INIT"+"(FREGIONCODE, FCATEGORYNUMBER, FCATEGORYNAME, FCATEGORYSUBCODE, FCATEGORYSUBNAME, FPAYITEMNUMBER, FPAYITEMNAME, FPAYITETYPE, FCATEGORYID, FCATEGORYSUBID)"
    sqlInsert=sqlInsert+" Values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);"
    cursTo.execute(sqlInsert,value)
    ()
#cursTo.execute(sqlStr)
#resultTo = cursFrom.fetchall()
#print(sqlInsert)
搜索更多相关主题的帖子: jdbc driver java oracle File 
2022-05-08 19:06
快速回复:如何批量把A库的数据插入到B库中
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017426 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved