python数据库编程 ODBC方式实现通讯录


Posted in Python onMarch 27, 2020

Python 数据库编程,ODBC方式实现通讯录,供大家参考,具体内容如下

#-*-coding:utf-8-*-
import pyodbc
import os
def SelectInfo(hcon,hcur):
 hcur.execute('select * from PassMapT')
 ptitle=('ID','Item','Pwd','other')
 print(ptitle)
 result=hcur.fetchall()
 for item in result:
 print(item)
 print('')

def AddInfo(hcon,hcur):
 id=int(input('please input ID: '))
 item=str(input('please input Item: '))
 pwd=str(input('please input Tel 1: '))
 other=str(input('please input Other: '))
 sql="insert into PassMapT(id,item,pwd,other) values(?,?,?,?)"
 try:
 hcur.execute(sql,(id,item,pwd,other))
 hcon.commit()
 except:
 hcon.rollback()

def DeleteInfo(hcon,hcur):
 SelectInfo(hcon,hcur)
 did=int(input('please input id of delete: '))
 sql="delete from PassMapT where id=?"
 try:
 hcur.execute(sql,(did,))
 hcon.commit()
 except:
 hcon.rollback()

def UpdateInfo(hcon,hcur):
 SelectInfo(hcon,hcur)
 did=int(input('please input id of update: '))
 
 sqlitem="update PassMapT set item=? where id=?"
 item=str(input('please input Item: '))
 try:
 hcur.execute(sqlitem,(item,did))
 hcon.commit()
 except:
 hcon.rollback()
 
 sqlpwd="update PassMapT set pwd=? where id=?"
 pwd=str(input('please input Pwd: '))
 try:
 hcur.execute(sqlpwd,(pwd,did))
 hcon.commit()
 except:
 hcon.rollback()
 
 sqlother="update PassMapT set other=? where id=?"
 other=str(input('please input other: '))
 try:
 hcur.execute(sqlother,(other,did))
 hcon.commit()
 except:
 hcon.rollback()
 
def Meau():
 print('1.diaplay')
 print('2.add')
 print('3.update')
 print('4.delete')
 print('5.cls')
 print('0.exit')
 sel=9
 while(sel>5 or sel<0):
 sel=int(input('please choice: '))
 return sel

def main():
 hcon = pyodbc.connect(r'DRIVER={SQL Server Native Client 11.0};SERVER=127.0.0.1;DATABASE=PasswordMap;UID=sa;PWD=lptpwd')
 hcur=hcon.cursor()
 
 while(True):
 sel=Meau()
 if(sel==1):
 SelectInfo(hcon,hcur)
 elif(sel==2):
 AddInfo(hcon,hcur)
 elif(sel==3):
 UpdateInfo(hcon,hcur)
 elif(sel==4):
 DeleteInfo(hcon,hcur)
 elif(sel==5):
 os.system('cls')
 else:
 break
 hcur.close()
 hcon.close()

if __name__=='__main__':
 main()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python使用htpasswd实现基本认证授权的例子
Jun 10 Python
线程和进程的区别及Python代码实例
Feb 04 Python
Python的Asyncore异步Socket模块及实现端口转发的例子
Jun 14 Python
Python脚本处理空格的方法
Aug 08 Python
Python运维自动化之nginx配置文件对比操作示例
Aug 29 Python
Pandas_cum累积计算和rolling滚动计算的用法详解
Jul 04 Python
python3 打印输出字典中特定的某个key的方法示例
Jul 06 Python
python同步windows和linux文件
Aug 29 Python
Python中生成一个指定长度的随机字符串实现示例
Nov 06 Python
使用pymysql查询数据库,把结果保存为列表并获取指定元素下标实例
May 15 Python
windows支持哪个版本的python
Jul 03 Python
python 监控服务器是否有人远程登录(详细思路+代码)
Dec 18 Python
django 读取图片到页面实例
Mar 27 #Python
django ListView的使用 ListView中获取url中的参数值方式
Mar 27 #Python
django列表筛选功能的实现代码
Mar 27 #Python
python实现猜数游戏
Mar 27 #Python
手把手教你安装Windows版本的Tensorflow
Mar 26 #Python
python pandas.DataFrame.loc函数使用详解
Mar 26 #Python
Python计算指定日期是今年的第几天(三种方法)
Mar 26 #Python
You might like
php adodb介绍
2009/03/19 PHP
php加密之discuz内容经典加密方式实例详解
2017/02/04 PHP
php封装的mongodb操作类代码
2017/08/06 PHP
php 读写json文件及修改json的方法
2018/03/07 PHP
javascript下查找父节点的简单方法
2007/08/13 Javascript
Javascript 同时提交多个Web表单的方法
2009/02/19 Javascript
JavaScript网页定位详解
2014/01/13 Javascript
jquery 通过name快速取值示例
2014/01/24 Javascript
技术男用来对妹子表白的百度首页
2014/07/23 Javascript
jQuery中ajax的load()与post()方法实例详解
2016/01/05 Javascript
微信小程序授权登录及解密unionId出错的方法
2018/09/26 Javascript
详解vantUI框架在vue项目中的应用踩坑
2018/12/06 Javascript
vue2.0+SVG实现音乐播放圆形进度条组件
2019/09/21 Javascript
基于vue-draggable 实现三级拖动排序效果
2020/01/10 Javascript
jquery实现垂直手风琴导航栏
2020/02/18 jQuery
关于JavaScript中异步/等待的用法与理解
2020/11/18 Javascript
Element-ui upload上传文件限制的解决方法
2021/01/22 Javascript
[56:57]LGD vs VP 2019DOTA2国际邀请赛淘汰赛 胜者组赛BO3 第一场 8.20.mp4
2019/08/22 DOTA
pycharm 使用心得(八)如何调用另一文件中的函数
2014/06/06 Python
Python的加密模块md5、sha、crypt使用实例
2014/09/28 Python
Python类的专用方法实例分析
2015/01/09 Python
用Python编写分析Python程序性能的工具的教程
2015/04/01 Python
Python常用小技巧总结
2015/06/01 Python
Windows下实现Python2和Python3两个版共存的方法
2015/06/12 Python
Python函数装饰器常见使用方法实例详解
2019/03/30 Python
django-rest-framework解析请求参数过程详解
2019/07/18 Python
对YOLOv3模型调用时候的python接口详解
2019/08/26 Python
html5+css3气泡组件的实现
2014/11/21 HTML / CSS
英国女性运动服品牌:Sweaty Betty
2018/11/08 全球购物
军校制空专业毕业生自我鉴定
2013/11/16 职场文书
英语国培研修感言
2014/02/13 职场文书
智慧人生:永远不需要向任何人解释你自己
2019/08/20 职场文书
MySQL触发器的使用
2021/05/24 MySQL
PHP实现两种排课方式
2021/06/26 PHP
Python实现自动玩连连看的脚本分享
2022/04/04 Python
动画《朋友游戏》公开佐藤友生绘制的开播纪念绘
2022/04/06 日漫