您的位置:首页 > 数据库 > Oracle

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

2015-10-27 12:32 645 查看
一,在安装的时候,参数有点不一样:

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: