且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在PYTHON中,用cx_Oracle连接ORACLE数据库简单示例

更新时间:2022-09-01 16:29:46

一,在安装的时候,参数有点不一样:

python setup.py build install

 

二,连接数据库,有两种方式,DSN和TNSNAMES方式:

#dsn = orcl.makedsn(self.oracle_host, self.oracle_port, self.oracle_sid)
#con = orcl.connect(self.oracle_username, self.oracle_password, dsn)
con = orcl.connect(self.oracle_username,self.oracle_password,self.oracle_alarm_ciname)
cursor = con.cursor()
sql = "select '%s'  from dual" % (test_str,)
cursor.execute(sql);
result = cursor.fetchall()
cursor.close()
con.close()

 

三,检测数据库是否正常的语句如下:

select 'OK'  from dual