Introduction To sqlite3 in Python by R4R Team

What is Database ?
-A database is an organized collection of data.
-Database handlers create database in such a way that only one set of software program provide access of data to all the users.
-The main purpose of database is to operate large amount of information by storing, retrieving and managing.

Database in Python:

To maintain a database, python provide many modules and supports wide range of database servers :
-GadFly
-mSQL
-MySql
-Infomix
-sqlite3
-sybase

What is sqlite3 ?

-sqlite3 is a python module written by Gerhard Haring for managing the database in the simplest way.

How install the sqlite3 ?

open command promt in your system and write the following command

pip install sqlite3


How use sqlite3 in your programming-

import sqlite3

write above line to use the sqlite3 in your program.

Steps to deals with the database :

-Create or open a database and establish the connection.
-Create or open a tables
-Execute query
-Close the connection

Create a database :

program-

import sqlite3

conn=sqlite3.connect('r4rDatabase.db')
if conn:
print("Database is successfully created")
else:
print("Error occur")

conn.close()


output-

Database is successfully created

-In this program, we firstly import the sqlite2 module by import sqlite3, then using connect() function we connect or open the database.
-Here if the database of such name is not exist then connect() fucntion create a database with that name otherwise it open the old database.
-conn is database object that are used further to perform other task on the database.
-close() function are used to close the database.




Leave a Comment: