oracle
import cx-Oracle import os os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8' # 设置oracle的编码为utf8 class Oracle: def __init__(self, user, password, host, port, sid): self.conn = cx_Oracle.connect(user, password, host + ':' + port + '/' + sid) self.cursor = self.conn.cursor() def execute(self, sql): self.cursor.execute(sql) self.conn.commit() def fetchall(self): return self.cursor.fetchall() def fetchone(self): return self.cursor.fetchone() def close(self): self.cursor.close() self.conn.close() def __del__(self): self.close() if __name__ == '__main__': oracle = Oracle('scott', 'tiger', '127.0.0.1', '1521', 'orcl') oracle.execute('select * from emp') print(oracle.fetchall()) oracle.close() del oracle print('oracle closed')