1.安装 sqlalchemy

Microsoft Windows [版本 6.1.7601]

版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

C:\Users\Administrator>easy_install SQLAlchemy

 

2.安装cx_Oracle扩展

根据python以及Oracle数据库版本确定下载cx_oracle库版本,并安装之。

 

3.测试连接

---- 导入sqlalchemy模块 ----

>>> from sqlalchemy import *

---- 创建连接引擎 ----

 

>>> db=create_engine('oracle://test:test@192.168.1.10:1521/oradb1')

注释:

用户名:test

密码:test

oracle数据库IP:192.168.1.10

连接端口:1521

数据库SID:oradb1

---- 执行数据库连接 ----

>>> conn = db.connect()

---- 执行SQL语句 ----

 

>>> res = conn.execute('select * from machine')

---- 显示结果集 ----

>>> for row in res:

...     print "Location IP : ", row['locationip']

...

Location IP :  192.168.2.10

>>>

---- 关闭数据库连接 ----

 

>>> conn.close()