博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
pyrhon3与mysql:查、更、删49
阅读量:4601 次
发布时间:2019-06-09

本文共 1432 字,大约阅读时间需要 4 分钟。

1 import pymysql 2  3 conn = pymysql.connect(host='localhost',user='root',passwd='123456',db='jodb1',port=3307,charset='utf8') 4 # 172.31.10.225 5  6 # 查询EMPLOYEE表中salary(工资)字段大于1000的所有数据: 7 cursor = conn.cursor() 8  9 10 print('1---------------------------------------------------------------------')11 sql = 'select * from employee where income > 2500'12 cursor.execute(sql)13 results = cursor.fetchall()14 try:15     for row in results:16         fname = row[0]17         lname = row[1]18         age = row[2]19         sex = row[3]20         income = row[4]21         print('first_name={0},last_name={1},age={2},sex={3},income={4}'.format(fname,lname,age,sex,income))22 23 except:24     print('oh,there a exception!')25 conn.close()26 print('select successfully')27 28 29 30 print('2---------------------------------------------------------------------')31 32 # sql_update = 'update employee set age = 28 where sex ={0}'.format('F')33 sql2 = "update employee set age = 28 where sex = '%c'"%('M')34 try:35     cursor.execute(sql2)36     conn.commit()37 except:38     conn.rollback()39     print('Execute this statement')40 41 42 print('3---------------------------------------------------------------------')43 44 sql3 = "delete from employee where income = '%d'"%(3900)45 try:46     cursor.execute(sql3)47     conn.commit()48 except:49     conn.rollback()

执行其中一部分时将其他部分删除,否则会有错误

转载于:https://www.cnblogs.com/jpr-ok/p/9258489.html

你可能感兴趣的文章
自定义分页
查看>>
[转]DELPHI——调试(1)
查看>>
JS秒数转成分秒时间格式
查看>>
xp_cmdshell 命令的开启与关闭,和状态查询
查看>>
Linux sudoers
查看>>
MySQL详解(18)-----------分页方法总结
查看>>
bzoj 4595 激光发生器
查看>>
multi cookie & read bug
查看>>
js时间转换
查看>>
(转载) Android Studio你不知道的调试技巧
查看>>
POJ2231 Moo Volume 递推 C语言
查看>>
struts2类型转换的具体流程
查看>>
Hdu 1203 I NEED A OFFER!
查看>>
php文件上传类
查看>>
CF219D Choosing Capital for Treeland
查看>>
luogu P3809 【模板】后缀排序
查看>>
JVM 调优工具
查看>>
SCTF 2014 pwn题目分析
查看>>
集合以及特殊集合
查看>>
USACO 2.2 Runaround Numbers
查看>>