免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3638 | 回复: 5
打印 上一主题 下一主题

关于pymssql问题?? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-12-25 14:18 |只看该作者 |倒序浏览
最近用到pymssql数据库链接模块
但使用以下方法后,无法执行,不知那位可以帮我解决
con = pymssql.connect(host='192.168.13.122',user='sa',password='',database='tempdb')
cur = con.cursor()
cur.execute("select * from username where name=? and age=?",("12",34))
rows = cur.fetchall()
print rows


以上代码提示无法工作,但文档上说明可以执行,请帮忙看一下

论坛徽章:
0
2 [报告]
发表于 2008-12-25 15:38 |只看该作者
请帖下具体错误代码和提示哦

论坛徽章:
0
3 [报告]
发表于 2008-12-25 18:40 |只看该作者
Traceback (most recent call last):
  File "D:\python\a.py", line 12, in <module>
    cursor.execute("select * from yhxx where yhbh=?",("100900888000508"))
  File "C:\Python25\Lib\site-packages\pymssql.py", line 126, in execute
    self.executemany(operation, (params,))
  File "C:\Python25\Lib\site-packages\pymssql.py", line 152, in executemany
    raise DatabaseError, "internal error: %s" % self.__source.errmsg()
pymssql.DatabaseError: internal error: None

论坛徽章:
0
4 [报告]
发表于 2008-12-26 09:19 |只看该作者
cursor.execute("select * from yhxx where yhbh=?",("100900888000508"))
这行改成下面的试试:
cursor.execute("select * from yhxx where yhbh=%s",("100900888000508"))

论坛徽章:
0
5 [报告]
发表于 2008-12-26 19:36 |只看该作者
原帖由 ragkk 于 2008-12-25 14:18 发表
cur.execute("select * from username where name=? and age=?",("12",34))

这是写法是不是受了.net里访问数据库参数替换的影响?另外既然访问 sqlserver就用ado好了,反正是在win下费这个劲非得绕到dbapi上有什么实质好处?非要用dbapi我到觉得还不如用adodbapi,或者pyodbc.

论坛徽章:
0
6 [报告]
发表于 2008-12-26 19:44 |只看该作者
cursor.execute("select * from yhxx where yhbh=%s",("100900888000508"))
这个我知道,但好像是错误的,应该是这样的
cursor.execute("select * from yhxx where yhbh=%s",("100900888000508",))
pymssql这个不好吗?我一般用什么数据库就用什么库,
mssql:pymssql
mysql:myssqldb
oracle:cx_Oracle
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP