Academic records using database connectivity in python program in 2021

Academic records using database connectivity in python program in 2021
Academic records using database connectivity in python program in 2021

Python Academic records using database connectivity in python program.


Python database connectivity:  A python database connectivity are very most and useful. the database is the most useful topic because our data are safe in the database.

import sqlite3 as lit

a=input("Enter Student Id:")

a=int(a)

b=input("Enter Student Name:")

c=input("Enter Student Email:")

d=input("Enter Student Address:")

e=input("Enter Student RollNo:")

e=int(e)

f=input("Enter Student Course:")

g=input("Enter Student PhoneNo:")

g=int(g)

db=lit.connect('StudentDB.db')

with db:

    h=db.cursor()

    h.execute('insert into studen(Id,Name,Email,Address,RollNo,Course,PhoneNo)VALUES(?,?,?,?,?,?,?)',(a,b,c,d,e,f,g))

    db.commit()

    print("Data Inserted Sucessfuly")

db.close()

*****OUTPUT*****

Enter Student Id:746647

Enter Student Name:Icoderweb

Enter Student Email:icoderweb@gamil.com

Enter Student Address:Dehli

Enter Student RollNo:767357536

Enter Student Course:MCA

Enter Student PhoneNo:6467648364

Data Inserted Sucessfuly

Localhost database connectivity in python.

import mysql.connector
con=mysql.connector.connect(user="root",password='',host="localhost",db="pythondb")
print("connection sucessfuly!!!!")
curser=con.cursor()
q=curser.execute("Create table login(UNAME text,UPASS text)")
values=("icoderweb","12345678")
curser.execute(q,values)
con.commit()
curser.close()
con.close()
print("data are inserted  successfully")


Database create localhost in python.

import mysql.connector
try:
    db=mysql.connector.connect(user="root",host="localhost",password='',db="pydatabase")
    print("Database Created successfuly")
    cur=db.cursor()
    q=cur.execute("Create table student(Name char(20),Email char(20),Adress char(30),Phone(20)")
    cur.execute(q)
    print("Table Created Successfuly")

    db.commit()
    cur.close()
    db.close()
except:
    print("database not Created successfully")


How to insert data in sqlite3 in python.

import sqlite3
user=(

     (1,'Ram','ram@gamil.com'),
     (2,'Shayam', 'shayam@gamil.com'),
     (3,'Rahul', 'rahul@gamil.com'),
     (4,'Ramesh', 'ramesh@gamil.com'),
)
db=sqlite3.connect('student.db')
with db:
     cur=db.cursor()
     cur.executemany('INSERT INTO user VALUES (?)',user)
     print("Data inserted succesfully")

Post a Comment

0 Comments