- 论坛徽章:
- 0
|
在用python连接数据库的时候有个问题解决不了,google和baidu均没好的答案,故来请教大家一下
[php]
#Program purpose:Change the data of SQL SERVER2000 into ORACLE
#Program author:Jiang Xiao Dan
#Program create time:September 2, 2008
import pymssql
import cx_Oracle
import sys
class Datatodata:
#Initial method
def __init__(self):
print "The program purpose is change the data of SQL SERVER2000 into ORACLE"
#Visit SQL SERVER 2000
def mssqlQuery(self):
n = 0
conOracle = cx_Oracle.connect("a", "b", "c")
cursorOracle = conOracle.cursor()
#sqlOracle = "insert into SALE_COST_MONTH_BAK(Billing_cycle_ID,Local_code,Cost_dept,Subject_code,Term_type,Cust_type,Net_unit,Debit_charge,create_date values("
try:
#Create SQL SERVER2000 connection
connection = pymssql.connect(host='1',user='2',password='3',database='4')
result = connection.cursor()
sql = "select top 20 Billing_cycle_ID,Local_code,Cost_dept,Subject_code,Term_type,Cust_type,Net_unit,Debit_charge,Create_date from SALE_COST_MONTH"
result.execute(sql)
except pymssql.OperationalError,error:
print "Error",error
else:
for i in result.fetchall():
n = n+1
#print i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8]
#param = (i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7])
#m = cursorOracle.execute(sqlOracle,param)
#sqlOracle = sqlOracle+i[0]+i[1]+i[2]+i[3]+i[4]+i[5]+i[6]+i[7]+i[8]+")"
cursorOracle.execute("insert into SALE_COST_MONTH_BAK(Local_code,Cost_dept,Subject_code,Term_type,Cust_type,Net_unit) values('"+i[1]+"','"+i[2]+"','"+i[3]+"','"+i[4]+"','"+i[5]+"','"+i[6]+"')")
conOracle.commit()
result.close()
connection.close()
cursorOracle.close()
conOracle.close()
print "Count:",n,"data"
print "End"
def main():
Datatodata().mssqlQuery()
if __name__=="__main__":
main()
[/php]
程序在“cursorOracle.execute("insert into SALE_COST_MONTH_BAK(Local_code,Cost_dept,Subject_code,Term_type,Cust_type,Net_unit) values('"+i[1]+"','"+i[2]+"','"+i[3]+"','"+i[4]+"','"+i[5]+"','"+i[6]+"')")”报错,错误信息是“Traceback (most recent call last):
File "D:\eclipse\workspace\redleaf\src\Datatodata.py", line 44, in <module>
main()
File "D:\eclipse\workspace\redleaf\src\Datatodata.py", line 42, in main
Datatodata().mssqlQuery()
File "D:\eclipse\workspace\redleaf\src\Datatodata.py", line 33, in mssqlQuery
cursorOracle.execute("insert into SALE_COST_MONTH_BAK(Local_code,Cost_dept,Subject_code,Term_type,Cust_type,Net_unit) values('"+i[1]+"','"+i[2]+"','"+i[3]+"','"+i[4]+"','"+i[5]+"','"+i[6]+"')")
TypeError: cannot concatenate 'str' and 'NoneType' objects”
请问这个问题怎么解决呢?谢谢大家 |
|