python cx_oracle sid连不上实际能连报超时_python3使用cx_Oracle连接oracle时,怎么传参sid或service_name...

importcx_Oracle as cxfrom quartz.comm.config importconfSqlclassOraclePy():def __init__(self,userName,password,host,port,connType,service_name): #标识是根据SID还是SERVICE_NAME连接

self.userName =userName

self.password=password

self.host=host

self.port=portif (connType == 'SID'):

self.con=cx.connect(self.userName, self.password, cx.makedsn(self.host, self.port, service_name))

self.cursor=self.con.cursor()elif(connType == "SERVICE_NAME"):

dns_tns= cx.makedsn(self.host, self.port, service_name=service_name)

self.con=cx.connect(self.userName,self.password,dns_tns)

self.cursor=self.con.cursor()else:print("不支持的数据库连接方式,当前只支持SID和SERVICE_NAME")#批量执行增删改sql

defexecuteSqls(self,sqls):for sql insqls:

self.cursor.execute(sql)

self.con.commit()#self.cursor.close

#self.con.close

#更新交易表

defupdateTxnCtrl(self,sql,idTxn):

sql= sql.replace("IDTXN",str(idTxn))

self.cursor.execute(sql)

self.con.commit()defupdateTxnCtrl1(self,sql,tunnelValue,idTxn):

sql= sql.replace('tunnelValue',str(tunnelValue)).replace("IDTXN",str(idTxn))

self.cursor.execute(sql)

self.con.commit()#self.cursor.close

#self.con.close

#更新交易表

defupdateTxnCtrl2(self, sql,value1 , value2, idTxn):

sql= sql.replace('tunnelValue1', str(value1)).replace('tunnelValue2', str(value2)).replace("IDTXN",str(idTxn))

self.cursor.execute(sql)

self.con.commit()#self.cursor.close

#self.con.close

#查询清分明细表

defClrTxnListQuery(self,sql,idTxn):

sql= sql.replace('idTxn',str(idTxn))

self.cursor.execute(sql)

col=[]

resultSets=[]for i inself.cursor.description:

col.append(i[0])for data inself.cursor.fetchall():

list2=(list(data))

resultSets.append(dict(map(lambdax, y: [x, y], col, list2)))returnresultSetsdefT_RPT_INAMT(self,sql):

self.cursor.execute(sql)

col=[]

resultSets=[]for i inself.cursor.description:

col.append(i[0])for data inself.cursor.fetchall():

list2=(list(data))

resultSets.append(dict(map(lambdax, y: [x, y], col, list2)))returnresultSets#关闭数据连接

defdisConnection(self):

self.cursor.close

self.con.closeif __name__ == '__main__':#conn = OraclePy('partner','partner','192.168.127.121',1530,'SID','billdb')

conn = OraclePy('QAMODIFY', 'bfjwc0qocjp0dlgf', '192.168.6.42', 1530, 'SERVICE_NAME', 'vposdbtaf')

sql= "select t.* from expt t"TrptInamt=conn.T_RPT_INAMT(sql)print(len(TrptInamt))print(TrptInamt)

conn.disConnection()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值