I am confused about why python needs cursor object. I know jdbc and there the database connection is quite intuitive but in python I am confused with cursor object. Also I a
As others mention, a Connection() is the network connection to the database, and it's only real use is to return cursors. PEP-249, where DBApi 2.0 is specified, does not clearly define what exactly a connection or cursor is, nor what the close() method on each must do; only that
must return an instance of
, that
must return an instance of
, and
should invoke the statement provided and return the resulting rows. In particular, it does not define a
, although specific implementations are free to implement them as extensions.
Depending on those extensions is probably unwise, though, since it means you won't have as portable code. DBApi makes this two-level requirement because having an execute on the connection without an intermediate object can be difficult on some databases.