def connect(date1,volumn1,price1,rise1,time1):
#print type(date1),volumn1,price1,rise1,time1
db=MySQLdb.connect("localhost","root","998426","stock")
cursor=db.cursor()
sql=" insert into tab1(date,volumn,price,rise,time) values(%s,%s,%f,%s,%s)"%(date1,volumn1,price1,rise1,time1)
#sql = "insert into tab1(date,volumn,price,rise,time) values('2017/9/13 星期二','200',17.5,'2.14%','15:30')" //this can work!
try:
cursor.execute(sql)
db.commit()
except:
db.rollback()
db.close()
date1,volumn1,rise1,time1是字符串;
price1是浮动;
答案 0 :(得分:0)
sql="insert into stock_CB(dates,volumn,price,rise,times) values('%s','%s',%f,'%s','%s')" % (date1.encode("utf-8"),volumn1.encode("utf-8"),price1,rise1.encode("utf-8"),time1.encode("utf-8"))
当我改变它时它可以工作。