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)

      

  • 相关阅读:
    centos安装杂记inittabhostnamessh
    centos6安装aircrack,reaver1.4
    20175236 201820192 《Java程序设计》第五周学习总结
    20175236 201820192 《Java程序设计》第三周学习总结
    20175236 JAVA MyCP(课下作业)
    20175236 201820192 《Java程序设计》第六周学习总结
    小学生之Java中的异常
    小学生之面向对象的三个特征继承、封装、多态
    小学生之类与对象
    小学生之手(01)之 "for循环"
  • 原文地址:https://www.cnblogs.com/bubutianshu/p/12895620.html
Copyright © 2011-2022 走看看