python3使⽤cx_Oracle连接oracle时,怎么传参sid或
service_name
使⽤cx_Oracle.makedsn连接oracle数据库时,如果⽤Service name不⽤SID,应该如下传参。
dns_tns=cx_Oracle.makedsn('host',port,service_name='service_name')
如果⽤SID不⽤Service name,应该如下传参。
dns_tns=cx_Oracle.makedsn('host',port,'sid_info')
或
dns_tns=cx_Oracle.makedsn('host',port,sid='sid_info')
import cx_Oracle as cx
fig import confSql
class OraclePy():
def__init__(self,userName,password,host,port,connType,service_name): # 标识是根据SID还是SERVICE_NAME连接
self.userName = userName
self.password = password
self.host = host
self.port = port
if (connType == 'SID'):
< = cx.connect(self.userName, self.password, cx.makedsn(self.host, self.port, service_name))
self.cursor = ursor()
elif(connType == "SERVICE_NAME"):
dns_tns = cx.makedsn(self.host, self.port, service_name=service_name)
< = cx.connect(self.userName,self.password,dns_tns)
self.cursor = ursor()
else:print("不⽀持的数据库连接⽅式,当前只⽀持SID和SERVICE_NAME")
# 批量执⾏增删改sql
def executeSqls(self,sqls):
for sql in sqls:
ute(sql)
# self.cursor.close
# lose
# 更新交易表
def updateTxnCtrl(self,sql,idTxn):
sql = place("IDTXN",str(idTxn))
ute(sql)
def updateTxnCtrl1(self,sql,tunnelValue,idTxn):
sql = place('tunnelValue',str(tunnelValue)).replace("IDTXN",str(idTxn))
ute(sql)
# self.cursor.close
# lose
# 更新交易表
def updateTxnCtrl2(self, sql,value1 , value2, idTxn):
sql = place('tunnelValue1', str(value1)).replace('tunnelValue2', str(value2)).replace("IDTXN",str(idTxn))
ute(sql)
# self.cursor.close
# lose
# 查询清分明细表
def ClrTxnListQuery(self,sql,idTxn):
sql = place('idTxn',str(idTxn))
ute(sql)
col = []
resultSets = []
for i in self.cursor.description:如何连接oracle数据库
col.append(i[0])
for data in self.cursor.fetchall():
list2 = (list(data))
resultSets.append(dict(map(lambda x, y: [x, y], col, list2)))
return resultSets
def T_RPT_INAMT(self,sql):
ute(sql)
col = []
resultSets = []
for i in self.cursor.description:
col.append(i[0])
for data in self.cursor.fetchall():
list2 = (list(data))
resultSets.append(dict(map(lambda x, y: [x, y], col, list2)))
return resultSets
# 关闭数据连接
def disConnection(self):
self.cursor.close
if__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()
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论