python连接服务器informix_python 如何连接informix

本文介绍了如何在Python中连接到Informix数据库。通过执行`setup.py`进行安装后,展示了一个示例程序,该程序打开到'stores'数据库的连接,执行SELECT查询,并根据特定条件删除记录。最后,它展示了有关Python和InformixDB的更多信息资源。
摘要由CSDN通过智能技术生成

| tar xvf -

cd python setup.py build_ext

python setup.py install

Example Program

#!/usr/bin/python

import sys

import informixdb  # import the InformixDB module

# ------------------------------------

# open connection to database 'stores'

# ------------------------------------

conn = informixdb.connect("stores")

# ----------------------------------

# allocate cursor and execute select

# ----------------------------------

cursor1 = conn.cursor(rowformat = informixdb.ROW_AS_DICT)

cursor1.execute('select code, sname from state')

# --------------------------

# prepare 'delete' statement

# --------------------------

cursor2 = conn.cursor()

# ---------------------

# fetch thru result set

# ---------------------

for row in cursor1:

# -------------------------------------------

# delete row if column 'code' begins with 'C'

# -------------------------------------------

if row['code'][0] == 'C':

cursor2.execute('delete from state where code = ?', (row['code'],))

print "DELETED: %-2s %-15s" % (row['code'], row['sname'])

continue

# --------

# show row

# --------

print "%-2s %-15s" % (row['code'], row['sname'])

# ---------------------------------------

# commit transaction and close connection

# ---------------------------------------

conn.commit()

conn.close()

sys.exit(0);

More Information on Python and InformixDB

Resource        Location/URL

Python Home        http://www.python.org

Learning Python        http://docs.python.org/tut/tut.html

Download DB-API InformixDB        DB-API InformixDB

C. Haese: The Python InformixDB API        python_dbi_khaese.pdf收起

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值