python数据库编程 ODBC方式实现通讯录
作者:Ugex 发布时间:2024-01-15 10:58:01
标签:python,ODBC,通讯录
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()
来源:https://blog.csdn.net/Ugex_Savelar/article/details/103056839
0
投稿
猜你喜欢
- 实际上在python中用列表就可以实现动态变量名的管理,python中的列表中可以存储任何类型的元素:listA = [0,"st
- 字典树(Trie)可以保存一些字符串->值的对应关系。基本上,它跟 Java 的 HashMap 功能相同,都是 key-value
- xpath表达式1. xpath语法<bookstore><book> <title lang="e
- 目录1、正则表达式1.1 正则表达式字符串1.1.1 元字符1.1.2 字符转义1.1.3 开始与结束字符1.2 字符类1.2.1 定义字符
- request获取post请求中的json数据def hello(request): data = json.loads(request.b
- 目录介绍:原理:1.标准import2.reload函数实现:总结:介绍:热更新,就是在服务器不重启的的情况下,对游戏增加新的功能或者修复出
- 代码演示如下:方法一<?php function encryptDecrypt($key, $string, $decrypt){
- 好多同志对 iframe 是如何控制的,并不是十分了解,基本上还处于一个模糊的认识状态.注意两个事项,ifr 是一个以存在的 iframe
- 创建变量变量是存放数据值的容器。与其他编程语言不同,Python 没有声明变量的命令。首次为其赋值时,才会创建变量。实例x = 10y =
- 经常会遇到这样一个情况:浏览器弹出对话框,提示脚本运行时间过长,询问“停止”还是“继续”。那究竟各个浏览器是如何判断在什么时候才弹出此对话框
- 起源当同一个远程服务器有多个人使用的时候,想知道服务器是否有人在用,我们不能直接的去登录,因为这样可能会把对方挤下来,这并不友好,所以这里提
- key123456value25201510530字典P={1:10,2:25,3:5,4:15,5:20,6:30}有以下3种迭代器:P.
- 本文为大家分享了python八皇后问题的解决方法,供大家参考,具体内容如下题目:给定一个 N*N 正方形棋盘,在上面放置 N个棋子,又叫皇后
- 在讲这个问题之前让我们来先看一段代码: dim sql_injdata,SQL_inj,SQL_Get,SQL_Data,Sql_
- 本文代码是使用python抓取京东小米8手机的配置信息首先找到小米8商品的链接:https://item.jd.com/7437788.ht
- 1、说明GIL规定一个Python解释程序只能同时由一个线程控制。在CPU限制类型和多线程代码中,GIL是一个性能瓶颈。GIL使Python
- 数据库的操作是当前系统开发必不可少的开发部分之一,尤其是在现在的大数据时代,数据库尤为重要。但是你真的懂得Java与数据库是怎么连接的么?先
- 什么是WaitGroupsWaitGroups是同步你的goroutines的一种有效方式。想象一下,你和你的家人一起驾车旅行。你的父亲在一
- 本文实例讲述了Python中map和列表推导效率比较。分享给大家供大家参考。具体分析如下:直接来测试代码吧:#!/usr/bin/env p
- 初识项目打开VS2015,创建Web项目,选择ASP.NET Web Application,在弹出的窗口里选择ASP.NET 5 Webs