python oracle 运维,mysql oracle python连接
#encoding:utf-8
#dataProc
#auth xiajikun
import sys
# oracle庫連接模塊
import cx_Oracle
# mysql庫連接
import MySQLdb
import time
import os
#水電煤庫
# SDM = 'username/password@ip:port/servicename'
DB_ORA_STR = 'admin/123456@10.1.1.2:1521/c9db1111'
# oracle連接
class OracleLogin(object):
#初始化,創(chuàng)建連接數(shù)據(jù)庫對象
def __init__(self, loginName):
#--建立連接
self.conn = cx_Oracle.connect(loginName)
#--獲取游標(biāo)
self.cursor = self.conn.cursor()
self.l_v_status = self.cursor.var(cx_Oracle.NUMBER)
self.l_v_return_code = self.cursor.var(cx_Oracle.STRING)
self.l_v_sno = self.cursor.var(cx_Oracle.STRING)
#查詢sql方法
def selectSql(self, sql):
self.cursor.execute(sql)
self.result_sql = self.cursor.fetchall()
self.count = self.cursor.rowcount
self.conn.commit()
#執(zhí)行sql方法
def execSql(self,sql):
self.cursor.execute(sql)
self.conn.commit()
#執(zhí)行存儲過程方法
def getMetaData(self,procdName, sql, procArgs):
self.procResult = self.cursor.callproc(procdName, procArgs)
self.cursor.execute(sql)
self.result_pro = self.cursor.fetchall()
self.count = self.cursor.rowcount
self.conn.commit()
#無用時(shí)自動析構(gòu)此對象
def __del__(self):
self.cursor.close()
self.conn.close()
# mysql連接
class MysqlLogin(object):
#初始化,自動連接數(shù)據(jù)庫
def __init__(self, db_str):
# self.conn = MySQLdb.connect(host='10.7.11.242',user='credcard',passwd='5sFVDVCeKo',db='credcard',port=3320)
self.conn = MySQLdb.connect(host=db_str[0],user=db_str[1],passwd=db_str[2],db=db_str[3],port=db_str[4])
#self.conn = MySQLdb.connect('%s' % db_str)
#self.conn = MySQLdb.connect('%s,%s,%s,%s,%d' % (db_str)
self.cur = self.conn.cursor()
def exec_sql(self, sql):
self.cur.execute(sql)
self.conn.commit()
def select_sql(self, sql):
self.cur.execute(sql)
self.tmpdata = self.cur.fetchall()
#自動斷開游標(biāo)和連接
def __del__(self):
self.cur.close()
self.conn.close()
db_str = ('10.1.1.1','username','123456','db_name',3306)
db_obj = MysqlLogin(db_str)
sql = 'select * from tabname limit 10'
db_obj.select_sql(sql)
print db_obj.tmpdata
總結(jié)
以上是生活随笔為你收集整理的python oracle 运维,mysql oracle python连接的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php中args,PHP中的重载,即__
- 下一篇: rds 数据库营销报告_千人千面的营销数