windows下python安装连接oracle安装包

来源:互联网 发布:淘宝拍单兼职能挣钱吗 编辑:程序博客网 时间:2024/06/02 02:20

python版本:2.7

本机有oracle客户端,连接服务器上的oracle,版本oracle10

1、下载python cx_Oracle模块

官方网址:下载地址(注意,看准版本,无论是系统、还是python、还是oracle不然报错,一旦报错首先考虑版本问题)

我下的是cx_Oracle-5.1.2-10g.win32-py2.7版本,版本比较低,下载后直接点击安装就行

如果你下载的是cx_Oracle-6.0.2-cp27-cp27m-win32.whl中,则需要在cmd中在文件目录下执行pip install cx_Oracle-6.0.2-cp27-cp27m-win32.whl

2、使用脚本中代码

import cx_Oraclecon = cx_Oracle.connect("user/passport@SID")cursor = con.cursor()cursor.execute("SELECT * FROM SS")row = cursor.fetchone()print row[3],cursor.close()con.close()

user是oracle用户名,password是密码,SID是oracle配置中的SID,在tnsnames.ora中

连接方式
1、con = cx_Oracle.connect("user","password","SID")

2、con = cx_Oracle.connect("user/password@SID")

3、con = cx_Oracle.connect('user','password','10.33.155.111:1521/SID')

4、con = cx_Oracle.connect('user/password@10.34.133.155:1521/SID')


原创粉丝点击