python数据库连接池

时间:2023-03-09 01:48:02
python数据库连接池
python数据库连接池
import psycopg2
import psycopg2.pool
dbpool=psycopg2.pool.PersistentConnectionPool(1,1,dbname='postgis',user='postgres',host='127.0.0.1',password='1',port='')
conn=dbpool.getconn()
cursor=conn.cursor()
sqlstr="select name,type,state from wy"
cursor.execute(sqlstr)
rows=cursor.fetchall()
for row in rows:
print "name",row[0]
print "type",row[1]
print "state",row[2]
print "***"
dbpool.putconn(conn)