python3 操作oralce的类(连接、查询、调用存储过程)

网友投稿 229 2022-08-29


python3 操作oralce的类(连接、查询、调用存储过程)

#!/usr/bin/python3# -*- coding: utf-8 -*-import cx_Oracleclass DBOracle: def __init__(self, user, pwd, url): self.url_ = url self.user_ = user self.pwd_ = pwd self.connection_ = None self.cursor_ = None def connect(self): try: self.connection_ = cx_Oracle.connect(self.user_, self.pwd_, self.url_) self.cursor_ = self.connection_.cursor() except cx_Oracle.DatabaseError as ex: raise Exception("cx_Oracle.DatabaseError:" + str(ex)) except Exception as ex: raise Exception("Exception:" + str(ex)) if self.connection_ is None or self.cursor_ is None: return False return True def query(self, sql, args=[]): try: self.cursor_.execute(sql, args) data = self.cursor_.fetchall() except cx_Oracle.DatabaseError as ex: raise Exception("cx_Oracle.DatabaseError:" + str(ex)) except Exception as ex: raise Exception("Exception:" + str(ex)) return data def execute(self, sql, args=[]): try: self.cursor_.execute(sql, args) self.connection_.commit() except cx_Oracle.DatabaseError as ex: raise Exception("cx_Oracle.DatabaseError:" + str(ex)) except Exception as ex: raise Exception("Exception:" + str(ex)) def call_proc(self, proc_name, args=[]): try: self.cursor_.callproc(proc_name, args) except cx_Oracle.DatabaseError as ex: raise Exception("cx_Oracle.DatabaseError:" + str(ex)) except Exception as ex: raise Exception("Exception:" + str(ex)) def call_func(self, proc_name, ret_type, args=[]): try: ret_value = self.cursor_.callfunc(proc_name, ret_type, args) except cx_Oracle.DatabaseError as ex: raise Exception("cx_Oracle.DatabaseError:" + str(ex)) except Exception as ex: raise Exception("Exception:" + str(ex)) return ret_value def close(self): self.cursor_.close() self.connection_.close()

包括oracle的连接、查询、调用存储过程、调用函数等功能。python


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:python的http代理服务脚本性能优化proxyHandler.py
下一篇:Java实现经典游戏飞机大战
相关文章

 发表评论

暂时没有评论,来抢沙发吧~