Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import psycopg2
- try:
- connection = psycopg2.connect(user = "admin",
- password = "1234",
- database = "esdata")
- cursor = connection.cursor()
- cursor.execute("SELECT * from student;")
- record = cursor.fetchall()
- for item in record:
- print item
- for i in range(10):
- 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
- cursor.execute(cmd)
- cursor.execute("SELECT * from student;")
- record = cursor.fetchall()
- for item in record:
- print item
- connection.commit()
- # print("You are connected to - ", type(record),"\n")
- except (Exception, psycopg2.Error) as error :
- print ("Error while connecting to PostgreSQL", error)
- finally:
- #closing database connection.
- if(connection):
- cursor.close()
- connection.close()
- print("PostgreSQL connection is closed")
Add Comment
Please, Sign In to add comment