?
config.py
# 數據庫測試環境 name = '***' password = '******' host_port_sid = '10.**.*.**:1521/bidbuat'
?
OracleOperation.py
import cx_Oracle import configclass OracleOperation(object):# 執行下面的execute_sql方法時會自動執行該初始化方法進行連接數據庫def __init__(self):# 建立連接self.conn = cx_Oracle.connect(config.name, config.password, config.host_port_sid)# 創建游標self.cursor = self.conn.cursor()def execute_sql(self, sql):"""執行sql語句,并commit提交:param sql:需要執行的sql語句:return:"""self.cursor.execute(sql)self.conn.commit()def get_data(self):"""獲得查詢數據:return: 返回查到的數據"""data = self.cursor.fetchall()return datadef close_oracle(self):# 關閉游標 self.cursor.close()# 關閉數據庫連接self.conn.close()
?