Hello all, I am currently doing an assignment that links python to SQL Developer, and I keep getting errors that my statements for "custCursor.execute" and "delivCursor.execute" are not properly ended, but I cannot figure out why. any help would be greatly appreciated, and the code is posted below. the first query "custIDCursor.execute" works great, and will even display everything that I need it to.
#Get Parameter for the CustIDQuery
prompt1 = '>'
print(f"Enter the Customer's Last Name: ")
lnameValue = input(prompt1)
# Set up cursor and retrieve data (Created by Joshua W. Baker)
custIDCursor = conn.cursor()
custIDCursor.execute("SELECT c.custno FROM customer c WHERE c.lname = '%s'" % lnameValue)
custIDValue = custIDCursor.fetchall()
print(custIDValue)
custCursor = conn.cursor()
custCursor.execute("SELECT c.fname, c.lname, c.city FROM customer c WHERE c.custno = '%s' " % custIDValue)
delivCursor = conn.cursor()
delivCursor.execute("SELECT b.bagno, b.deliverydatetime, b.runno FROM bag b WHERE b.custno = '%s' " % custIDValue)
Solved! Go to Solution.
What happens when you add
custValue = custCursor.fetchall()
and
delivValue = delivCursor.fetchall()
under your two statements that are erroring? It looks like you are setting them up but not executing them and since you are using the same conn without garbage collecting, the previous is staying open.
You may also trying to set them up in with statements so they are garbage collected and resources released before the next cursor is created using the same conn.
with conn.cursor() as custCursor:
custCursor.execute(f"SELECT c.fname, c.lname, c.city FROM customer c WHERE c.custno = '{custIDValue}'")
custValue = custCursor.fetchall()
What happens when you add
custValue = custCursor.fetchall()
and
delivValue = delivCursor.fetchall()
under your two statements that are erroring? It looks like you are setting them up but not executing them and since you are using the same conn without garbage collecting, the previous is staying open.
You may also trying to set them up in with statements so they are garbage collected and resources released before the next cursor is created using the same conn.
with conn.cursor() as custCursor:
custCursor.execute(f"SELECT c.fname, c.lname, c.city FROM customer c WHERE c.custno = '{custIDValue}'")
custValue = custCursor.fetchall()
This is exactly what needed to be done, thanks so much for your help! I’m new to SQL so combining it with python was a struggle for me.
Does the .execute() string need to be terminated with a semicolon?