#-*-coding:cp936-*-
import pymssql #这个模块你自己上网找一下
##class SqlDataBase:
conn = pymssql.connect(host='192.168.0.114',user='charles',password='charles',database='newsforPDA')
cursor = conn.cursor()
##resource='select id,new_date from uploadnews'
##cursor.execute(resource,())
##print cursor.description
cursor.execute(" INSERT INTO newsbycharles (title,content,raw_link,new_date,system_date,source) VALUES('%s','%s','%s','%s','%s','%s') "%('测试',u'abcd',u'http://abc',u'1800-1-1',u'1800-1-1',u'test2')) # 你可以自己写代码拼接出语句
##cursor.execute(" update table1 set col1 .... " ) #\u751f\u547d\u65f6\u62a5
conn.commit() # 提交
conn.close() # 关闭
raw_input('finished')
the warm is:
Quote
>>>
Traceback (most recent call last):
File "E:\学习资料\python improve\using20101203\class\softwareforupload_collection\复件 python upload to SQL 组件.py", line 10, in <module>
cursor.execute(" INSERT INTO newsbycharles (title,content,raw_link,new_date,system_date,source) VALUES('%s','%s','%s','%s','%s','%s') "%('测试',u'abcd',u'http://abc',u'1800-1-1',u'1800-1-1',u'test2')) # 你可以自己写代码拼接出语句
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb2 in position 88: ordinal not in range(128)
>>>
Traceback (most recent call last):
File "E:\学习资料\python improve\using20101203\class\softwareforupload_collection\复件 python upload to SQL 组件.py", line 10, in <module>
cursor.execute(" INSERT INTO newsbycharles (title,content,raw_link,new_date,system_date,source) VALUES('%s','%s','%s','%s','%s','%s') "%('测试',u'abcd',u'http://abc',u'1800-1-1',u'1800-1-1',u'test2')) # 你可以自己写代码拼接出语句
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb2 in position 88: ordinal not in range(128)
>>>
Edited by Roger, 14 February 2012 - 01:59 PM.
added code tags


Sign In
Create Account

Back to top









