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='5432')
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)

 

转载自:https://blog.csdn.net/weixin_34072857/article/details/86081734

You may also like...

退出移动版