python查询db2数据库数据_[数据库测试]强烈推荐一个python ODBC数据源插件,可支持Oracle,Db2,Mysql,Sql-server以及各种数据库版本,附例子和测试程序...

今天有很多时间,再与大家分享一个最近使用的到第三方控件,个人认为对设计一些数据库测试脚本非常有用。

这为我们通过Windows系统,制作各种测试脚本提供很好操作平台。DB-API:http://www.python.org/dev/peps/pep-0249/

None.gifDownload

None.gifAsuccessfulinstallationofmxODBCrequiresthesethreesteps:

None.gif

None.gifBeforecontinuingwiththedownloadofmxODBC,firstmakesurethatyouhaveinstalledtheeGenix.commxBaseDistribution,sincetheeGenix.commxODBCDistributionisanadd-ontoourbasesetofPythonextensions.

None.gifThedownloadsbelowdonotcontainanylicensekeys.Youwilleitherhavetoobtainevaluationlicensesorbuyproductionlicensesinordertosuccessfullyinstallandusethepackage.

None.gifSelecttherightdownloadforyourplatformandPythonversionandthenheadontotheinstallationinstructionsbelow.

None.gifIMPORTANT:

None.gifBydownloading,installingorusingtheeGenixmxODBCDistribution,youagreetothetermsandconditionssetforthintheeGenix.comCommercialLicenseAgreement1.2.0.

None.gifRedistributionofthesefilesisnotallowed.PleasecontacttheeGenixSalesTeamfordetailsaboutredistributionpossibilitiesandterms.

下载控件清单:

egenix-mx-base-3.0.0.win32-py2.5.msegenix-mx-experimental-3.0.0.win32-py2.5.msi

egenix-mxodbc-3.0.1.win32-py2.5.msi

注册License

eGenix.comCommercialLicenseAgreement1.2.0,注意填好后,Liscense会被发送到邮箱

Lincense拷贝的路径,本机地址:C:/Python25/Lib/site-packages/mx/ODBC

如果没有注册Liscense,会有如下提示:

以下提供一段测试程序,该段程序为清除Db2中的两表数据:

None.gif#-*-coding:cp936-*-None.gifimportmx.ODBC

None.gifimportmx.ODBC.Windows

None.gif

None.gifIDLE中提示:

None.gifTraceback(mostrecentcalllast):

None.gifFile"E: tpSearch_Table.py",line3,inmodule>None.gifimportmx.ODBC.Windows

None.gifFile"mxODBCWindows__init__.py",line9,inmodule>None.gifImportError:initializationofmodulemxODBCfailed(class'mx.ODBC.Windows.LicenseError'>:mx.ODBC.licensecouldnotbeloaded;pleasevisitthehttp://www.egenix.com/web-sitetoobtainalicensefileorwritetolicenses@egenix.comforinformation.)

None.gif

None.gif提取有效部分:licensecouldnotbeloaded;pleasevisitthehttp://www.egenix.com/web-sitetoobtainalicensefileorwritetolicenses@egenix.comforinformation

None.gif#-*-coding:cp936-*-None.gifimportmx.ODBC

None.gifimportmx.ODBC.Windows

None.gifimportsys,os,time

None.gif

None.gifclassdb2_test():

None.gif

None.gifdef__init__(self,tablename1,tablename2):

None.gifself.tablename1=tablename1

None.gifself.tablename2=tablename2

None.gifprintself.tablename1,self.tablename2

None.gif

None.gif#清除任意制定表数据None.gifdeftruncate_table(self):

None.gifdb=mx.ODBC.Windows.DriverConnect('DSN=infospy')

None.gifcursor=db.cursor()

None.gifcursor.execute("ALTERTABLE%sACTIVATENOTLOGGEDINITiALLYWITHEMPTYTABLE;"%(self.tablename1))

None.gifcursor.execute("ALTERTABLE%sACTIVATENOTLOGGEDINITiALLYWITHEMPTYTABLE;"%(self.tablename2))

None.gifcursor.execute("Commit;")

None.gifcursor.close()

None.gifdb.close()

None.gifprint"表%s;%s;清除数据成功!"%(self.tablename1,self.tablename2)

None.gif

None.gifif__name__=="__main__":

None.giftablename1="test_table_1"None.giftablename2="test_table_2"None.gifdb2=db2_test(tablename1,tablename2)

None.gifdb2.truncate_table()

None.giftime.sleep(3)

None.gifsys.exit(1)

db=mx.ODBC.Windows.DriverConnect('DSN=infospy') DSN为在WindowsODBC中配置的数据源名

有关ODBC配置,此贴略。由于时间关系,详细的API请查询文章中所给的地址。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值