python之oracle连接 cx_Oracle

1,根据平台下载http://cx-oracle.sourceforge.net/安装包

2,在windows下安装cx_Oracle-5.0-10g.win32-py2.6.msi

3,如果报DLL加载失败的错误错误,请下载http://download.csdn.net/source/3080197及http://download.csdn.net/source/3080200,解压把其中全部文件放到Python26/Lib/site-packages下

4,import cx_Oracle      #导入模块
>>> db = cx_Oracle.connect('hr', 'hrpwd', 'localhost:1521/XE') 建立连接,3个参数分开写

>>> db1 = cx_Oracle.connect('hr/hrpwd@localhost:1521/XE') 建立连接,3 个参数连写
>>> dsn_tns = cx_Oracle.makedsn('localhost', 1521, 'XE')
>>> print dsn_tns
(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
(CONNECT_DATA=(SID=XE)))
>>> db2 = cx_Oracle.connect('hr', 'hrpwd', dsn_tns)
>>> print db.version
10.2.0.1.0
5,具体使用参照cx_oracle的API: http://cx-oracle.sourceforge.net/html/index.html

你可能感兴趣的:(python之oracle连接 cx_Oracle)