Connection.py 482 B

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