i want to insert the data into a PostgreSQL database but when i try to insert data is not stored in the database and error is not generated so I am unable to find out what the error is, please help
#!/usr/bin/python
import psycopg2
import psycopg2.extras
import sys
con = None
try:
con = psycopg2.connect("dbname='mydb' user='merlin' host='192.168.0.104' password='merlin123'")
cursor = con.cursor(cursor_factory=psycopg2.extras.DictCursor)
cursor.execute("SELECT * FROM table1")
rows = cursor.fetchall()
except psycopg2.DatabaseError, e:
print 'Error %s' % e
finally:
if con:
con.close()
try:
con = psycopg2.connect("dbname='mydb2' user='merlin' host='192.168.0.104'")
cursor = con.cursor(cursor_factory=psycopg2.extras.DictCursor)
query = "INSERT INTO table3 VALUES ('%s', '%s', '%d' , %s)" % (raw[0][0], raw[0][1],raw[0][2],0)
#while raw!=None:
cursor.execute(query)
con.commit()
except psycopg2.DatabaseError, e:
print 'Error %s' % e
finally:
if con:
con.close()
sys.exit(1)
Can anyone help solving the error?