Search code examples
pythonsqlpgadmin-4

My code doesn't actually insert into the database


I don't run into any error messages anymore but when i refresh my database nothing is actually injected? using psycopg2 and pgadmin4

import psycopg2 as p

con = p.connect("dbname =Feedbacklamp user =postgres password= fillpw host=localhost port=5432")
cur = con.cursor()
sql = "INSERT INTO audiolevels(lokaalnummer,audiolevel,tijdstip) VALUES (%s,%s,%s)"
val = "100"
val1 = 100
val2 = "tijdstip"

cur.execute(sql,(val,val1,val2))
con.commit
cur.close
con.close

The values to be inserted into my pgadmin sql database


Solution

  • con.commit() should be a function call I think is your problem. You are missing the parentheses which treats it as member access instead of a function call. This also goes for the other methods cur.close() and con.close()