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)

      

  • 相关阅读:
    【SpringCloud构建微服务系列】分布式链路跟踪Spring Cloud Sleuth
    【算法】LRU算法
    细说分布式锁
    【Python】Python3.4+Matplotlib详细安装教程
    LoRaWAN协议(二)--LoRaWAN MAC数据包格式
    LoRaWAN移植笔记(一)__RTC闹钟链表的实现
    cJSON_json包的C语言解析库
    LoRaWAN协议(一)--架构解析
    STM32L051 PVD的调试
    以帧为存储单位的循环stack
  • 原文地址:https://www.cnblogs.com/bubutianshu/p/12895620.html
Copyright © 2011-2022 走看看