python代码简洁,准备利用其读取数据库中数据,生成csv文件,然后导入到另一个库中,因两台数据库网络不通;本次先测试oracle的代码。
下载相应的库cx_Oracle-5.2.1-11g.win-amd64-py3.4,与python版本一致,同时注意操作系统的位数,我这里是64位系统。网址:https://pypi.python.org/pypi/cx_Oracle/5.2.1
import cx_Oracle
conn = cx_Oracle.connect('userName/pwd@192.168.0.192/orcl')
cur = conn.cursor()
cur.execute("select user_name,user_real_name,update_date from sys_user where id = '10000'")
row =cur.fetchone() #返回元祖
for f in row:
print(f)
cur.close()
conn.close()
代码确实简洁。不过显然是测试代码,没有通用性,查找下有没有java中类似的dbutils、mybatis之类工具,在别人肩膀上做点实用工具;google下,确实有,记录如下供参考。
SQLAlchemy
SQLAlchemy is the Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL.
Django
Django for web applications, exploiting its built-in ORM capabilities.
本文介绍如何使用Python及cx_Oracle库连接并从Oracle数据库读取数据的方法,并提供了简单的示例代码。此外,还探讨了提高代码复用性和扩展性的途径,包括SQLAlchemy等工具。
7905

被折叠的 条评论
为什么被折叠?



