Wednesday, 19 June 2019

Database connectivity SQLite

Database Connectivity:

 #Step1 import the sqlite

import sqlite3 as s

#step2:

conn=s.connect('escdb.db')

print("Database opened successfully")

 Steps:

To create

 Persistanece: OOP’s

Class,object, abstraction,encapsulation,inheritance,polymorphsm…persistence

Files…

Java, python,…

 


To store the data we can use:

Files or database.

 File: A file can data in the secondary memory ex: hard disk. It can store text format or binary format. Data is stored unformatted

 

Database: collection of data. We can store the data in the database

Once the data is stored in a database, we need to perform operations on data.

 

Operations:

Modification to the existing data

Deletion for unnecessary data

Reading /Retrieving the data from the database

These operations is called Database Management systems (DMBS)

 

Dbms=db+application(Java/Python/…)

 

Advantages of DBMS:

 

1.     Storing and retrieving the data is so simple to compared to files by

Using SQL(Structured Query Language) Commands we can perform.

2.     We can not store the huge amount of data in the files whereas we can store in Database

3.     Relationship is not possible to maintain in the files

4.     Multiple users can retrieve or access the database simultaneously.

5.     If any changes are done, we can not rollback to the files

6.     Files are very weak security. Whereas DBMS Offers good security.

 

Example 2:

#creating table

#import the sqlite

import sqlite3 as s

conn=s.connect('escdb.db')

print("Database opened successfully")

conn.execute('''CREATE TABLE APSSDC(

ID INT PRIMARY KEY NOT NULL,

NAME TEXT NOT NULL,

AGE INT NOT NULL,

ADDRESS CHAR(50),

SALARY REAL);''')

print("Table created successfully")

conn.close()

"""

Database opened successfully

Table created successfully

"""

 

Steps to connect to SQLite:

1.     Import the module. Ex: import sqlite3.

2.     Use connect() method of a sqlite3 module and pass the actual parameter  with database name as an parameter/argument. Ex: conn=s.connect('escdb.db')

3.     Perform sql operations: Example: conn.execute(‘’’……’’’’)

 

Import sqlite3: we can use all the classes,method  of sqlite3 module

Sqlite3.connect(): We can create connection to the SQLite Database.

 

If you want to use any database, first we should be installed in our system then only we can create database.

 

We have so many database in the market:

1.     Oracle

2.     GadFly

3.     mSQL

4.     MySQL

5.     PostgreSQL

6.     Microsoft SQL Server 2000

7.     IBM DB2

SAP DB… etc


No comments:

Post a Comment

Files with Exception handling

#Ask the user to take two input integer values var a,b try:     a=int(input("enter any integer value:"))     b=int(input(&qu...