Home > Articles > Programming > Java

  • Print
  • + Share This
From the author of

Prepared Statements

The executemany() cursor method is the Python DB API equivalent to Java's prepared statement. In reality, other statements executed are prepared in zxJDBC, but the executemany() method allows you to use question marks for values in the SQL statement. The second argument to executemany() is a tuple of values that replaces the question marks in the SQL statement:

>>> sql = "INSERT INTO random (letter, number) VALUES (?, ?)"
>>> cur.executemany(sql, ('Z', 51))
>>> # view the row
>>> cur.execute("SELECT * from random where letter='Z'")
>>> cur.fetchall()
[('Z', 51, 24)]
  • + Share This
  • 🔖 Save To Your Account