Guest User

Untitled

a guest
Dec 9th, 2018
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import psycopg2
  2. try:
  3. connection = psycopg2.connect(user = "admin",
  4. password = "1234",
  5. database = "esdata")
  6. cursor = connection.cursor()
  7. cursor.execute("SELECT * from student;")
  8. record = cursor.fetchall()
  9. for item in record:
  10. print item
  11. for i in range(10):
  12. cmd = "insert into student(name,age, gender, contact_no, course, address, qualification_10, qualification_12) values ('subham', 20, 'M', '999222833%s', 'IT', 'blore', 90, 80);" % i
  13. cursor.execute(cmd)
  14. cursor.execute("SELECT * from student;")
  15. record = cursor.fetchall()
  16. for item in record:
  17. print item
  18. connection.commit()
  19. # print("You are connected to - ", type(record),"\n")
  20. except (Exception, psycopg2.Error) as error :
  21. print ("Error while connecting to PostgreSQL", error)
  22. finally:
  23. #closing database connection.
  24. if(connection):
  25. cursor.close()
  26. connection.close()
  27. print("PostgreSQL connection is closed")
Add Comment
Please, Sign In to add comment