Connection.py 515 B

12345678910111213141516171819202122232425
  1. '''
  2. Created on 2018年12月19日
  3. @author: User
  4. '''
  5. import psycopg2
  6. from DBUtils.PooledDB import PooledDB
  7. #使用连接池访问数据库
  8. pool = None
  9. def getConnection():
  10. global pool
  11. if pool is None:
  12. pool = PooledDB(psycopg2, 10,dbname="BiddingKG", host="192.168.2.101",user="postgres",password="postgres",port="5432")
  13. return pool.connection()
  14. if __name__=="__main__":
  15. conn = getConnection()
  16. cursor = conn.cursor()
  17. cursor.execute(" select 1")
  18. print(cursor.fetchall()[0][0])