• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
SnowerS
博客园    首页    新随笔    联系   管理    订阅  订阅
Python 结缘Oracle、MySQL

Oracle http://cx-oracle.sourceforge.net/html/index.html
模块名称:cx_Oracle

 

#!/usr/bin/python


import cx_Oracle

connstr='scott/tiger'
conn = cx_Oracle.connect(connstr)
curs = conn.cursor()
curs.execute('select * from emp')
print curs.description
for row in curs:
print row
conn.close()



MySQL http://mysql-python.sourceforge.net/MySQLdb.html
模块名称:MySQLdb

 1 #!/usr/bin/python
2
3 import MySQLdb
4
5 conn = MySQLdb.connect (host = "localhost",user = "testuser",passwd = "testpass",db = "test")
6 cursor = conn.cursor ()
7 cursor.execute ("SELECT VERSION()")
8 row = cursor.fetchone ()
9 print "server version:", row[0]
10 cursor.close ()
11 conn.close ()

 

posted on 2012-03-31 21:19  SnowerS  阅读(202)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3