zoukankan      html  css  js  c++  java
  • oracle数据库操作(结合读取.ini文件操作)

    # -*- coding:utf-8 -*-
    import cx_Oracle
    from Util import readConfig
    from Util.log import Logger
    
    
    Config = readConfig.ReadConfig()
    
    class ConfigOracle:
        def __init__(self):
            self.dbname = None
            self.log = Logger()
            self.logger = self.log.get_log()
            self.db = None
            self.cursor = None
    
        def connectDB(self):
        #读取.ini文件里的方法 host = Config.get_db(self.dbname, "host") username = Config.get_db(self.dbname, "username") password = Config.get_db(self.dbname, "password") port = Config.get_db(self.dbname, "port") database = Config.get_db(self.dbname, "database")

         #oracle数据库操作 dns = cx_Oracle.makedsn(str(host), int(port), database) try: self.db = cx_Oracle.connect(username, password, dns) self.cursor = self.db.cursor() # print("数据库连接成功") except cx_Oracle.DatabaseError: self.logger.error("账号密码错误,数据库登录失败") except ConnectionError as ex: self.logger.error(str(ex)) def executeSQL(self, sql): self.connectDB() try: self.cursor.execute(sql) self.db.commit() except Exception: self.logger.error("sql为空!") return self.cursor # fetchall()函数,它的返回值是多个元组,即返回多个行记录,如果没有结果,返回的是() def get_all(self, cursor): value = cursor.fetchall() return value # fetchone()函数它的返回值是单个的元组,也就是一行记录,如果没有结果,那就会返回null def get_one(self, cursor): value = cursor.fetchone() return value def closeDB(self): self.db.close() # print("数据库关闭!") if __name__ == '__main__': db = ConfigOracle() db.dbname = "CREDIT5DB" cursor = db.executeSQL("select t.*,rowid from lb_t_customter_info t where cust_code=(select fk_cust_code from lb_t_into_info where into_app_id='130154740318')") res = db.get_one(cursor)[3] print(res)

      

  • 相关阅读:
    期望DP入门(p1850换教室)
    P2858 [USACO06FEB]奶牛零食Treats for the Cows
    2019 CCF夏令营 day 2
    2019 CCF夏令营 day 1
    双向存图解题
    P3952 时间复杂度
    P1347 排序(拓扑排序)
    清理Docker垃圾
    k8s中command、args和dockerfile中entrypoint、cmd之间的作用
    kubectl命令自动补全
  • 原文地址:https://www.cnblogs.com/bubutianshu/p/12895620.html
Copyright © 2011-2022 走看看