␡
- Connecting to the Database
- Cursor
- zxJDBC and MetaData
- Prepared Statements
- Errors and Warnings
- dbexts
- About This Article
Like this article? We recommend
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)]