Python3.x:pyodbc调用sybase的存储过程
示例代码
# python3 # author lizm # datetime 2018-03-02 17:00:00 # -*- coding: utf-8 -*- from datetime import datetime import datetime, time import sys import pyodbc def doPro(): r_code = 0 try: #过程名 proc = 'p_python20180302' #参数 applyid = 'station' sql = ['declare @c_applyid varchar(50) ' ] sql.append(' select @c_applyid =%s ' ) sql.append(" execute %s @applyid = @c_applyid " ) sql = ''.join(sql) % (applyid,proc) # 打开数据库连接z` conn = pyodbc.connect("DSN=147;UID=DBA;PWD=sql") # 获取一个游标 cursor = conn.cursor() try: # 执行sql语句 cursor.execute(sql) # 提交到数据库执行 conn.commit() r_code = 0 except: # 如果发生错误则回滚 conn.rollback() r_code = 1 cursor.close() # 关闭游标 conn.close() # 释放数据库资源 except: r_code = 1 print("存储过程调用失败") return r_code # 测试 if __name__ == '__main__': doPro()
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/16764.html