In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-11-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The following mainly brings you mysql oracle python connection methods, I hope these contents can bring you practical use, which is also the main purpose of this article I edit mysql oracle python connection methods. All right, don't talk too much nonsense, let's just read the following.
# encoding:utf-8
# dataProc
# auth xiajikun
Import sys
# oracle Library connection Module
Import cx_Oracle
# mysql Library connection
Import MySQLdb
Import time
Import os
# Hydropower and coal depot
# SDM = 'username/password@ip:port/servicename'
DB_ORA_STR = 'admin/123456@10.1.1.2:1521/c9db1111'
# oracle connection
Class OracleLogin (object):
# initialize and create a connection database object
Def _ _ init__ (self, loginName):
#-establish a connection
Self.conn = cx_Oracle.connect (loginName)
#-get cursors
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)
# query sql method
Def selectSql (self, sql):
Self.cursor.execute (sql)
Self.result_sql = self.cursor.fetchall ()
Self.count = self.cursor.rowcount
Self.conn.commit ()
# execute sql method
Def execSql (self,sql):
Self.cursor.execute (sql)
Self.conn.commit ()
# execute stored procedure method
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 ()
# automatically destruct this object when it is useless
Def _ del__ (self):
Self.cursor.close ()
Self.conn.close ()
# mysql connection
Class MysqlLogin (object):
# initialize and automatically connect to the database
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 _ department% s _ r% s _ r% 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 ()
# automatically disconnect cursors and connections
Def _ del__ (self):
Self.cur.close ()
Self.conn.close ()
Db_str = ('10.1.1.1) 123456 (' 10.1.1.1)
Db_obj = MysqlLogin (db_str)
Sql = 'select * from tabname limit 10'
Db_obj.select_sql (sql)
Print db_obj.tmpdata
For the above about mysql oracle python connection method, we do not think it is very helpful. If you need to know more, please continue to follow our industry information. I'm sure you'll like it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.