小风儿 发表于 2018-6-14 13:46:53

Windows 平台sqlalchemy 连接oracle数据库

  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()
页: [1]
查看完整版本: Windows 平台sqlalchemy 连接oracle数据库