import os import sys import psycopg2 def connectPostgreSQL(): conn = psycopg2.connect(database="testdb", user="postgres", password="new.1234", host="127.0.0.1", port="5432") print 'connect successful!' if __name__=='__main__': connectPostgreSQL()
import os
import sys
import psycopg2
def connectPostgreSQL():
conn = psycopg2.connect(database="testdb", user="postgres", password="new.1234", host="127.0.0.1", port="5432")
print 'connect successful!'
cursor=conn.cursor()
cursor.execute('''create table public.member(
id integer not null primary key,
name varchar(32) not null,
password varchar(32) not null,
singal varchar(128)
)''')
conn.commit()
conn.close()
print 'table public.member is created!'
if __name__=='__main__':
connectPostgreSQL()
import os
import sys
import psycopg2
def connectPostgreSQL():
conn = psycopg2.connect(database="testdb", user="postgres", password="new.1234", host="127.0.0.1", port="5432")
print 'connect successful!'
cursor=conn.cursor()
cursor.execute('''create table public.member(
id integer not null primary key,
name varchar(32) not null,
password varchar(32) not null,
singal varchar(128)
)''')
conn.commit()
conn.close()
print 'table public.member is created!'
def insertOperate():
conn = psycopg2.connect(database="testdb", user="postgres", password="new.1234", host="127.0.0.1", port="5432")
cursor=conn.cursor()
cursor.execute("insert into public.member(id,name,password,singal)\
values(1,'member0','password0','signal0')")
cursor.execute("insert into public.member(id,name,password,singal)\
values(2,'member1','password1','signal1')")
cursor.execute("insert into public.member(id,name,password,singal)\
values(3,'member2','password2','signal2')")
cursor.execute("insert into public.member(id,name,password,singal)\
values(4,'member3','password3','signal3')")
conn.commit()
conn.close()
print 'insert records into public.memmber successfully'
if __name__=='__main__':
#connectPostgreSQL()
insertOperate()
import os
import sys
import psycopg2
def connectPostgreSQL():
conn = psycopg2.connect(database="testdb", user="postgres", password="new.1234", host="127.0.0.1", port="5432")
print 'connect successful!'
cursor=conn.cursor()
cursor.execute('''create table public.member(
id integer not null primary key,
name varchar(32) not null,
password varchar(32) not null,
singal varchar(128)
)''')
conn.commit()
conn.close()
print 'table public.member is created!'
def insertOperate():
conn = psycopg2.connect(database="testdb", user="postgres", password="new.1234", host="127.0.0.1", port="5432")
cursor=conn.cursor()
cursor.execute("insert into public.member(id,name,password,singal)\
values(1,'member0','password0','signal0')")
cursor.execute("insert into public.member(id,name,password,singal)\
values(2,'member1','password1','signal1')")
cursor.execute("insert into public.member(id,name,password,singal)\
values(3,'member2','password2','signal2')")
cursor.execute("insert into public.member(id,name,password,singal)\
values(4,'member3','password3','signal3')")
conn.commit()
conn.close()
print 'insert records into public.memmber successfully'
def selectOperate():
conn = psycopg2.connect(database="testdb", user="postgres", password="new.1234", host="127.0.0.1", port="5432")
cursor=conn.cursor()
cursor.execute("select id,name,password,singal from public.member where id>2")
rows=cursor.fetchall()
for row in rows:
print 'id=',row[0], ',name=',row[1],',pwd=',row[2],',singal=',row[3],'\n'
conn.close()
if __name__=='__main__':
#connectPostgreSQL()
#insertOperate()
selectOperate()
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ========== RESTART: C:\Users\Administrator\Desktop\mutilpleTest.py ========== id= 3 ,name= member2 ,pwd= password2 ,singal= signal2 id= 4 ,name= member3 ,pwd= password3 ,singal= signal3 >>>
import os
import sys
import psycopg2
def connectPostgreSQL():
conn = psycopg2.connect(database="testdb", user="postgres", password="new.1234", host="127.0.0.1", port="5432")
print 'connect successful!'
cursor=conn.cursor()
cursor.execute('''create table public.member(
id integer not null primary key,
name varchar(32) not null,
password varchar(32) not null,
singal varchar(128)
)''')
conn.commit()
conn.close()
print 'table public.member is created!'
def insertOperate():
conn = psycopg2.connect(database="testdb", user="postgres", password="new.1234", host="127.0.0.1", port="5432")
cursor=conn.cursor()
cursor.execute("insert into public.member(id,name,password,singal)\
values(1,'member0','password0','signal0')")
cursor.execute("insert into public.member(id,name,password,singal)\
values(2,'member1','password1','signal1')")
cursor.execute("insert into public.member(id,name,password,singal)\
values(3,'member2','password2','signal2')")
cursor.execute("insert into public.member(id,name,password,singal)\
values(4,'member3','password3','signal3')")
conn.commit()
conn.close()
print 'insert records into public.memmber successfully'
def selectOperate():
conn = psycopg2.connect(database="testdb", user="postgres", password="new.1234", host="127.0.0.1", port="5432")
cursor=conn.cursor()
cursor.execute("select id,name,password,singal from public.member where id>2")
rows=cursor.fetchall()
for row in rows:
print 'id=',row[0], ',name=',row[1],',pwd=',row[2],',singal=',row[3],'\n'
conn.close()
def updateOperate():
conn = psycopg2.connect(database="testdb", user="postgres", password="new.1234", host="127.0.0.1", port="5432")
cursor=conn.cursor()
cursor.execute("update public.member set name='update ...' where id=2")
conn.commit()
print "Total number of rows updated :", cursor.rowcount
cursor.execute("select id,name,password,singal from public.member")
rows=cursor.fetchall()
for row in rows:
print 'id=',row[0], ',name=',row[1],',pwd=',row[2],',singal=',row[3],'\n'
conn.close()
if __name__=='__main__':
#connectPostgreSQL()
#insertOperate()
#selectOperate()
updateOperate()
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ========== RESTART: C:\Users\Administrator\Desktop\mutilpleTest.py ========== Total number of rows updated : 1 id= 1 ,name= member0 ,pwd= password0 ,singal= signal0 id= 3 ,name= member2 ,pwd= password2 ,singal= signal2 id= 4 ,name= member3 ,pwd= password3 ,singal= signal3 id= 2 ,name= update ... ,pwd= password1 ,singal= signal1 >>>
import os
import sys
import psycopg2
def connectPostgreSQL():
conn = psycopg2.connect(database="testdb", user="postgres", password="new.1234", host="127.0.0.1", port="5432")
print 'connect successful!'
cursor=conn.cursor()
cursor.execute('''create table public.member(
id integer not null primary key,
name varchar(32) not null,
password varchar(32) not null,
singal varchar(128)
)''')
conn.commit()
conn.close()
print 'table public.member is created!'
def insertOperate():
conn = psycopg2.connect(database="testdb", user="postgres", password="new.1234", host="127.0.0.1", port="5432")
cursor=conn.cursor()
cursor.execute("insert into public.member(id,name,password,singal)\
values(1,'member0','password0','signal0')")
cursor.execute("insert into public.member(id,name,password,singal)\
values(2,'member1','password1','signal1')")
cursor.execute("insert into public.member(id,name,password,singal)\
values(3,'member2','password2','signal2')")
cursor.execute("insert into public.member(id,name,password,singal)\
values(4,'member3','password3','signal3')")
conn.commit()
conn.close()
print 'insert records into public.memmber successfully'
def selectOperate():
conn = psycopg2.connect(database="testdb", user="postgres", password="new.1234", host="127.0.0.1", port="5432")
cursor=conn.cursor()
cursor.execute("select id,name,password,singal from public.member where id>2")
rows=cursor.fetchall()
for row in rows:
print 'id=',row[0], ',name=',row[1],',pwd=',row[2],',singal=',row[3],'\n'
conn.close()
def updateOperate():
conn = psycopg2.connect(database="testdb", user="postgres", password="new.1234", host="127.0.0.1", port="5432")
cursor=conn.cursor()
cursor.execute("update public.member set name='update ...' where id=2")
conn.commit()
print "Total number of rows updated :", cursor.rowcount
cursor.execute("select id,name,password,singal from public.member")
rows=cursor.fetchall()
for row in rows:
print 'id=',row[0], ',name=',row[1],',pwd=',row[2],',singal=',row[3],'\n'
conn.close()
def deleteOperate():
conn = psycopg2.connect(database="testdb", user="postgres", password="new.1234", host="127.0.0.1", port="5432")
cursor=conn.cursor()
cursor.execute("select id,name,password,singal from public.member")
rows=cursor.fetchall()
for row in rows:
print 'id=',row[0], ',name=',row[1],',pwd=',row[2],',singal=',row[3],'\n'
print 'begin delete'
cursor.execute("delete from public.member where id=2")
conn.commit()
print 'end delete'
print "Total number of rows deleted :", cursor.rowcount
cursor.execute("select id,name,password,singal from public.member")
rows=cursor.fetchall()
for row in rows:
print 'id=',row[0], ',name=',row[1],',pwd=',row[2],',singal=',row[3],'\n'
conn.close()
if __name__=='__main__':
#connectPostgreSQL()
#insertOperate()
#selectOperate()
#updateOperate()
deleteOperate()
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ========== RESTART: C:\Users\Administrator\Desktop\mutilpleTest.py ========== id= 1 ,name= member0 ,pwd= password0 ,singal= signal0 id= 3 ,name= member2 ,pwd= password2 ,singal= signal2 id= 4 ,name= member3 ,pwd= password3 ,singal= signal3 id= 2 ,name= update ... ,pwd= password1 ,singal= signal1 begin delete end delete Total number of rows deleted : 1 id= 1 ,name= member0 ,pwd= password0 ,singal= signal0 id= 3 ,name= member2 ,pwd= password2 ,singal= signal2 id= 4 ,name= member3 ,pwd= password3 ,singal= signal3 >>>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有