0% found this document useful (0 votes)
19 views17 pages

Computer Science Project

Uploaded by

nivashstark765
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views17 pages

Computer Science Project

Uploaded by

nivashstark765
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

VANI VIDYALAYA

SENIOR SECONDARY AND JUNIOR COLLEGE


Affiliated to CBSE - New Delhi (Aff.No .1930186)
No.12, VENBULIAMMAN KOIL STREET, WEST K. K. NAGAR, CHENNAI 600 078

COMPUTER
SCIENCE PROJECT

SESSION : 2024 - 25

NAME : K.SRINIVASH
CLASS AND SECTION : XII - A
TOPIC : SQL AND PYTHON CONNECTIVITY
TEACHER INCHARGE : AKILA. K
SUB CODE : 083
REGISTRATION NUBER : ___________________________
VANI VIDYALAYA
SENIOR SECONDARY AND JUNIOR COLLEGE
Affiliated to CBSE - New Delhi (Aff.No .1930186)
No.12, VENBULIAMMAN KOIL STREET, WEST K. K. NAGAR, CHENNAI 600 078

CERTIFICATE
Certified to be bonafide record of the work done by
Selvan K. SRINIVASH of XII Std A Section
in the COMPUTER SCIENCE Laboratory during in the
Academic Year 2024 - 25

Registration Number

Staff - in - Charge principal

Submited for the Practical Examination held on __________________

Internal Examinar External Examinar


TABLE OF CONTENTS

SNO DESCRIPTION PG NO

1) ACKNOWLEDGEMENT 4

2) INTRODUCTION TO PYTHON 5

3) OBJECTIVES OF THE PROJECT 6

4) HARDWARE AND SOFTWARE REQUIREMENTS 7

5) DATABASE , TABLE & FUNCTIONS USED 8

10
6) SOURCE CODES

13
7) OUTPUTS

8) BIBLIOGRAPHY 16

3
ACKNOWLEDGEMENT

Apart from my efforts, the success of any project depends largely on


the encouragement and guidelines of many others. I take this
opportunity to express my gratitude to the people who have been
instrumental in the successful completion of this project.

I express a deep sense of gratitude to almighty God for giving me


strength for the successful completion of the project.

I express my heartfelt gratitude to my Parents for constant


encouragement while carrying out this project.

I gratefully acknowledge the contribution of the individuals who


contributed in bringing this project up to this level, who continues to
look after me despite my flaws,

I express my deep sense of gratitude to The Principal


Ms.A.Vidhyavathi who has been continuously motivating and
extending their helping hand to us.

I express my sincere thanks to Ms.Akila.K, our Computer Science


Teacher for constant encouragement and the guidance provided during
this project

4
INTRODUCTION TO PYTHON

Python is a dynamic, interpreted ( byte code-compiled)


language. There are no type declarations of variable,
parameters, functions or methods in the source code.
This makes the code short and flexible and you lose the
compile time type checking of the source code. Python
tracks the types of all values at runtime and flags code
that does not make sense as it runs.
Python was designed for readability and has some
similarities to the English Language with influence
from mathematics.
Python uses new line to complete a command as
opposed to other programming languages which
often use semicolons or parentheses.
Python relies on indentation using whitespace to
define scope; such as the scope of loops, functions,
and classes. Other programming languages often
use curly brackets for this purpose.
Advantages of Python
1. Easy to Read, Learn and Write.
2. Improved Productivity
3. Interpreted Language.
4. Free and Open – Source.
5. Vast Libraries Support.
6. Portability
Disadvantages of Python
1. Slow Speed
2. Not Memory Efficient
3. Weak in Mobile Computing.
4. Run Time errors.
5
OBJECTIVES OF THE PROJECT

Establish a connection: Successfully connect to a SQL


database (e.g., MySQL, PostgreSQL, SQLite) from a
Python application.
Perform CRUD operations: Implement Create, Read,
Update, and Delete (CRUD) operations using
Python to interact with the SQL database.
Retrieve and manipulate data: Use Python to retrieve
data from the SQL database, perform data
manipulation and analysis, and store the results back
in the database.
Implement data validation and error handling:
Ensure that data inserted into the database is valid
and handle errors that may occur during database
interactions.
Optimize database queries: Use efficient SQL queries
and indexing to optimize data retrieval and
manipulation.

6
HARDWARE AND SOFTWARE
REQUIREMENTS

I. OPERATING SYSTEM : WINDOWS 7 AND ABOVE

II. PROCESSOR: PENTIUM(ANY)

III. MOTHERBOARD:1.845 OR 915,995 FOR PENTIUM

IV. RAM:512MB+

V. Hard disk: 40 GB OR ABOVE

7
DATABASE , TABLE & FUNCTIONS USED

MySQL is a popular open-source relational database management system


(RDBMS) that uses Structured Query Language (SQL) to manage and
manipulate data.

Key Features:
1. Open-source and free to use
2. Supports SQL and various programming languages
3. Scalable and high-performance
4. Supports various data types and storage engines
5. Robust security features

Database Name : STARK_INDUSTRIES


Table Name : EMP 1

FUNCTIONS USED :

PYTHON IN-BUILT :
PRINT() - The print() function in Python is used to output text or values
to the screen. It is a built-in function that can take multiple arguments.
Syntax:
print(object(s), sep=separator, end=endvalue, file=fileobject)
CURSOR() - In Python, a cursor is an object that allows you to interact
with a database. It is used to execute SQL queries and retrieve data from
a database.
Key Features:
1. Connect to a database using a library such as sqlite3 or mysql-connector-python.
2. Create a cursor object using the cursor() method.
3. Execute SQL queries using the execute() method.
4. Fetch data using the fetchone(), fetchmany(), or fetchall() methods.
5. Close the cursor and connection when finished.

COMMIT () - method in Python is used to commit changes made to a


database. It is a part of the connection object in a database connection.
Syntax:
connection.commit()
8
FETCHONE () - method in Python is used to retrieve the next row of a
query result set, returning a single tuple or None if no more rows are
available.
Syntax:
cursor.fetchone()

FETCHALL () - method in Python is used to retrieve all rows of a query


result set, returning a list of tuples.
Syntax:
cursor.fetchall()

INT () -The INT() function in Python is used to convert a value to an


integer.
Syntax:
int(value)

INPUT () - function in Python is used to get user input. It returns a string


that the user enters.
Syntax:
input(prompt)

SQL COMMANDS :

INSERT - statement in SQL is used to add new records to a database table.


Syntax:
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);

UPDATE - statement in SQL is used to modify existing records in a database table.


Syntax:
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE
condition;

SELECT - statement in SQL is used to retrieve data from a database table.


Syntax:
SELECT column1, column2, ... FROM table_name;

DELETE - statement in SQL is used to delete existing records from a database table.
Syntax:
DELETE FROM table_name WHERE condition;

CREATE - The CREATE statement in SQL is used to create a new database table or
other database objects such as indexes, views, and triggers.
Syntax:
CREATE TABLE table_name ( column1 data_type, column2 data_type, .... );

9
SOURCE CODE

#=====================================================
import mysql.connector as a
p = str(input('ENTER THE PASSWORD FOR YOUR SQL '))
d = str(input('ENTER THE NAME OF THE DATABASE: '))
e = list(input('ENTER THE NAME OF THE TABLE: '))
b = a.connect(host = 'localhost',user = 'root', passwd = p,database = d)
C = b.cursor()
C.execute('select * from emp1 ;')
while True :
data = C.fetchone()
if data != None:
print('|',data[0],'|',data[1],'|',data[2],'|',data[3],'|')
else:
break
#=====================================================
def emp1_insert_rec():
C = b.cursor()
c1 = int(input('ENTER ID FOR COL 1:'))
c2 = str(input('ENTER NAME FOR COL 2:'))
c3 = str(input('ENTER JOB FOR COL 3:'))
c4 = int(input('ENTER SALARY FOR COL 4:'))
C.execute('insert into emp1 values({},"{}","{}",{})'.format(c1,c2,c3,c4))
b.commit()
#=====================================================

def emp1_update_rec():
C = b.cursor()
ch = int(input('ENTER THE FIELD DATA TO BE UPDATED : (job - 1/salary - 2) : '))
if ch == 2:
rol = int(input('ENTER THE ID (PRIMARY KEY):'))
sal = int(input('ENTER SALARY TO BE UPDATED :'))
C.execute('update emp1 set salary = {} where id = {};'.format(sal,rol))
b.commit()

10
elif ch ==1 :
rol = int(input('ENTER THE ID (PRIMARY KEY):'))
job = str(input('ENTER JOB TO BE UPDATED :'))
C.execute('update emp1 set job = "{}" where id = {};'.format(job,rol))
b.commit()
#==========================================================
def emp1_delete_rec():
C = b.cursor()
i = int(input('ENTER THE ID (PRIMARY KEY):'))
C.execute('delete from emp1 where id = {}'.format(i))
b.commit()

#==========================================================

def emp1_view_allrec():
ch = int(input('VIEW ALL RECORD (1) OR SPECIFICE REC (2) : '))
if ch == 1:
C = b.cursor()
C.execute('select * from emp1 ;')
print('-'*50)
while True:
data = C.fetchone()
if data != None:
print('|',data[0],'|',data[1],'|',data[2],'|',data[3],'|')
else:
break
print('-'*50)
elif ch == 2:
C = b.cursor()
i = int(input(' ENTER THE ID OF THE REC TO BE DISPLAYED : '))
C.execute('select * from emp1 where id= {}'.format(i))
data = C.fetchall()
print(data)
else :
print('wrong choice type again')

#==========================================================

11
#==========================================================

while True:
ch=int(input('MENU,\n1) INSERT,\n2) UPDATE,\n3) DELETE,\n4) VIEW RECORD,\n5) EXIT,\n(1/2/3/4/5) : '))

print('\n')
if ch == 1:
a = int(input('ENTER THE NO.OF ROWS TO BE INSERTED:'))
print('\n')
for i in range(0,a):
emp1_insert_rec()
print('\n')
elif ch == 2:
emp1_update_rec()
print('\n')
elif ch == 3:
emp1_delete_rec()
print('\n')
elif ch == 4:
emp1_view_allrec()
print('\n')
else:
break

#==========================================================

12
OUTPUTS

STORED RECORDS AND DATA MANUPULATION MENU :

INSERTE

UPDATE

13
DELETE

VIEW

14
TABLE CREATED IN MY SQL :

STRUCTURE OF THE TABLE :

15
BIBLIOGRAPHY

1) Computer science With Python - Class XII


By : Sumita Arora
2) MySQL
3) IDLE Python
4) META AI
5) Canva

16
THANK
YOU

17

You might also like