- mysql 数据库连接
import pymysql
conn = pymysql.connect(host=127.0.0.1, port=3306, user=root, password=1234, db=数据库名称, autocommit=True)
cursor = conn.cursor()
# 添加语句
sql = ‘’‘insert into Z_SQL (record, title, sqldata) values ("%s","%s","%s") ‘’’ % (insert_record, inputtext, inputsqldata)
cursor.execute(sql)
# 删除语句
sql = 'DELETe FROM Z_SQL WHERe record =%s ’
cursor.execute(sql, delete_no)
# 查找
sql = ‘SELECT* FROM Z_SQL’
cursor.execute(sql)
# 处理结果集
for line in cursor.fetchall():
print(line)
# 更新
sql = ‘’‘update Z_SQL set title ="%s",sqldata ="%s" where record ="%s" ‘’’ % (update_title, update_sqldata, update_no)
cursor.execute(sql)
- Oracle 数据库连接
import cx_Oracle
conn=cx_Oracle.connect(user,password,ip+":"+port)
cursor=conn.cursor()
# 删除语句
sql = f’’‘DELETE FROM Z_SQL WHERe record =’{delete_no}’ ‘’’
cursor.execute(sql)
# 添加语句
sql = f’’’ INSERT INTO Z_SQL(record, title, sqldata) values (’{insert_record}’,’{inputtext}’,’{inputsqldata} ‘) ‘’’
cursor.execute(sql)
conn.commit()
# 更新
sql = f’’‘update Z_SQL set title =’ {update_title} ‘, sqldata =’ {update_sqldata} ’ where record =’{update_no}’ ‘’’
cursor.execute(sql)
conn.commit()
# 查找
sql = ‘SELECT* FROM Z_SQL’
cursor.execute(sql)
# 处理结果集
for line in cursor.fetchall():
- Sqlserver 数据库连接
mport pymssql
conn=pymssql.connect(ip,user,password,db,autocommit=True)
cursor=conn.cursor()
# 添加语句
sql =’’‘insert into Z_SQL (record, title, sqldata) values (’%s’,’%s’,’%s’) ‘’’ % (insert_record, inputtext, inputsqldata)
cursor.execute(sql)
# 删除语句
sql = 'DELETe FROM Z_SQL WHERe record =%s ’
cursor.execute(sql, delete_no)
# 更新
sql = ‘’‘update Z_SQL set title =’%s’,sqldata =’%s’ where record =’%s’ ‘’’ % (update_title, update_sqldata, update_no)
cursor.execute(sql)
# 查找
sql = ‘SELECT* FROM Z_SQL’
cursor.execute(sql)
# 处理结果集
for line in cursor.fetchall():
print(line)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)