Connect SQLite with PythonFirst you have to install Python and SQLite on your syatem. Install PythonUse the following code: Press y and installation will be completed within seconds. Install SQLiteInstallation steps type in the following command: After installation check installation, sqlite terminal will give you a prompt and version info ? Go to desired folder and create database: sqlite3 database.db It’ll create database.db in the folder you’ve given the command. To check if your database is created, use the following command in sqlite3 terminal: Note: To connect SQLite with Python, you do not need to install the connection module separately because its being shipped by default along with Python version 2.5.x onwards.SQLite with PythonCreate a python file “connect.py”, having the following code: Execute the following statement on command prompt: Now connection is created with the javatpoint database. Now you can create a table. Create a tableCreate a table “Employees” within the database “javatpoint”. Create a python file “createtable.py”, having the following code: Execute the following statement on command prompt: A table “Employees” is created in the “javatpoint” database. Insert RecordsInsert some records in “Employees” table. Create a python file “connection.py”, having the following code: Execute the following statement on command prompt: Records are inserted successfully. Select RecordsNow you can fetch and display your records from the table “Employees” by using SELECT statement. Create a python file “select.py”, having the following code: Execute the following statement on command prompt: See all the records you have inserted before. By same procedures, you can update and delete the table in SQLite database usnig Python.
|
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/263756.html