CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
DanielBarnes18

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: DanielBarnes18/IBM-Data-Science-Professional-Certificate
Path: blob/main/07. Data Analysis with Python/Using DB-API Notes.ipynb
Views: 4586
Kernel: Unknown Kernel

Writing code using DB-API

The following format of code should be used when using the DB-API:

#Necessary import from dbmodule import connect #Create connection object connection = connect('databasename', 'username', 'password') #Create a cursor object cursor = connection.cursor() #Run queries cursor.execute('select * from mytable') results = cursor.fetchall() #Free resources up Cursor.close() connection.close()