import cx_Oracle
class dao:
__conn=None
__crusor=None
def get_conn(self):
host = 'localhost'
port = '1521'
dbase = 'testsid'
login = 'scott'
passwrd = 'tigger'
dsn = cx_Oracle.makedsn(host, port, dbase)
print (dsn)
conn = cx_Oracle.connect(login, passwrd, dsn)
self.__conn=conn
return
def get_cursor(self):
self.__cursor=self.__conn.cursor ()
def exec(self,sql):
self.__cursor.execute (sql)
result = self.__cursor.fetchall ()
return result
def close_crusor(self):
self.__cursor.close ()
def close_conn(self):
self.__conn.close ()
测试:
from simplecrawl.db import dao
ins=dao()
ins.get_conn()
ins.get_cursor()
result=ins.exec("select * from emp t")
for row in result:
print (row)
print ("=============")
result=ins.exec("select * from emp t")
for row in result:
print (row)
ins.close_crusor()
ins.close_conn()