Steps for creating database connectivity applications
• Start Python
• Import the packages required for database programming
• Open a connection to the database
• Create a cursor instance
• Execute a query or sql statement
• Extract data from result set
• Clean up the environment
Methods
Of cursor
object
Property
Of cursor
[Link] property of cursor object that returns the number of rows retrieved so far.
object
Using fetchall()
Id name
1 A
2 B
3 c
Data=[ (1,”A”), (2,”B”),(3,”c”)]
Data=[Link]()
(1,”A”)
Data=[Link](2)
[(1,”a”),(2,”b)]
Data=[Link](1)
[(1,”a”)]
Using fetchmany()
Using fetchone()
Using string method format()
%s replaced by value in tuple