Python program for SQL Command

 A simple python program to execute SQL starement


import sqlite3

con=sqlite3.connect("D:\Programs\SQL\dinesh_kumar.db")

cur=con.cursor()

print("CONNECTION SUCCESFUL")

def sql_execute(roll,name,dob,avg,place):

    x="INSERT INTO my_files (rollno,Name,dob,average,place) VALUES("+roll+","+name+","+dob+","+avg+","+place+")"

    cur.execute(x)

    connection.commit()

total=int(input("Enter no of records to be inserted:"))

for i in range(1,total+1,1):

    print("Enter the rollno for row no.",i,": ",end=" ")

    rollno=input()

    print("Enter name for row no.",i,": ",end=" ")

    name=input()

    print("Enter dob in format 'YYYY-MM-DD' for row no.",i,": ",end=" ")

    dob=input()

    print("Enter the average mark for row no.",i,": ",end=" ")

    avg=input()

    print("Enter the place for record no.",i,": ",end=" ")

    place=input()

    sql_execute(rollno,name,dob,avg,place)

print("Program sucessfuly inserted the record")


Comments

Popular Posts