0% found this document useful (0 votes)
140 views49 pages

Lab Manual File: Course Coordinator

The document describes mapping an ER/EER diagram to a relational database schema. There are three main steps: 1) Regular entity types are mapped to relations that include the entity's simple attributes and primary key. 2) Weak entity types are mapped to relations that include the weak entity's attributes plus a foreign key to the owner entity's primary key. 3) One-to-one relationship types can be mapped by adding a foreign key to one of the related entity's relations.

Uploaded by

Akshat Tarate
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)
140 views49 pages

Lab Manual File: Course Coordinator

The document describes mapping an ER/EER diagram to a relational database schema. There are three main steps: 1) Regular entity types are mapped to relations that include the entity's simple attributes and primary key. 2) Weak entity types are mapped to relations that include the weak entity's attributes plus a foreign key to the owner entity's primary key. 3) One-to-one relationship types can be mapped by adding a foreign key to one of the related entity's relations.

Uploaded by

Akshat Tarate
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/ 49

Mahavir Education Trust's

SHAH & ANCHOR KUTCHHI ENGINEERING COLLEGE


Chembur, Mumbai - 400 088
UG Program in Artificial Intelligence & Data Science

LAB MANUAL FILE

DATABASEMANAGEMENT SYSTEM(LAB)[CSL402]

Course Coordinator
MS.POOJA PRAJAPATI

Assistant Professor
Department of Artificial Intelligence & Data Science

2021-2022
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING COLLEGE
Chembur, Mumbai - 400 088
UG Program in Artificial Intelligence & Data Science

Lab Code CSL402 Lab Name DATABASE MANAGEMENT


SYSTEM
Academic Year 2021-2022 Semester IV
Class SE-13 Course Incharge MS.POOJA PRAJAPTI

Laboratory Outcomes (LO)


LO No. LO Statement (At the end of the course, students will be able to …) BL
1 Construct ER and EER diagram for the real life problem with software tool. 3

Apply different rules for Creating and updating database and tables with 3
2
different DDL and DML statements.

3 Apply integrity constraints and provide security to data. 3

4 Construct simple and Complex SQL queries. 3

5 Apply triggers and procedures for specific module/task 3

Illustrate Handing of concurrent transactions and access data through front 3


6
end (using JDBC ODBC connectivity.)
List of Experiments

Page no.
Sr. No. Title

1 Design an Entity-Relationship (ER) / Extended Entity-


Relationship (EER) Model for the given case study and detail
statement of problem.

2 Perform mapping ER/EER to Relational schema model.

3 Write Data Definition Language (DDL) and DML Commands to


populate database for the given specified System.

4 Write Integrity Constraints for the specified system

5 Write Simple queries, string manipulation operations for the


given statement of problem.

6 Write Nested queries and Complex queries for the given


statement of problem.

7 Perform Join operations for the given statement of problem

8 Write Views and Triggers for the given statement of problem.

9 Write Functions and procedure for the given statement of


problem

10 Perform Transaction and Concurrency control for the given


statement of problem

11 Write a Program to perform database connectivity (JDBC-


ODBC).

Name: Signature:
Date:
Experiment No. 1

Aim: Design an Entity-Relationship (ER) / Extended Entity-Relationship (EER)


Model for the given case study and detail statement of problem.

Theory:The ER model defines the conceptual view of a database. It works around


real-world entities and the associations among them.

Entity:An entity can be a real-world object, either animate or inanimate, that can be
easily identifiable.

An entity can be a real-world object, either animate or inanimate, that can be


easily identifiable. For example, in a school database, students, teachers, classes,
and courses offered can be considered as entities

An entity set is a collection of similar types of entities.


Attributes-Entities are represented by means of their properties, called attributes.
All attributes have values. For example, a student entity may have name, class,
and age as attributes.
Types of Attributes
 Simple attribute − Simple attributes are atomic values, which
cannot be divided further.
For example, a student's phone number is an atomic value of 10 digits.
 Composite attribute − Composite attributes are made of more than
one simple attribute.
For example, a student's complete name may have first_name and
last_name.
 Derived attribute − Derived attributes are the attributes that do not exist in
the physical database, but their values are derived from other attributes
present in the database.
For another example, age can be derived from data_of_birth.
 Single-value attribute − Single-value attributes contain
single value. For example − Social_Security_Number.
 Multi-value attribute − Multi-value attributes may contain more than
one values. For example, a person can have more than one phone
number, email_address, etc.
Relationship

The association among entities is called a relationship. For example, a student


enrols in a course. Here, enrols acts as a relationship.

Degree of Relationship

The number of participating entities in a relationship defines the degree of the


relationship.

Mapping Cardinalities

Cardinality defines the number of entities in one entity set, which can be
associated with the number of entities of other set via relationship set.

 One-to-one
 One-to-many
 Many-to-one
 Many-to-

many ER Diagram

Notations:
Symbol Meaning

Entity

Weak Entity

Relationship

Attribute
Key Attribute

Multivalued
Attribute

Composite
Attribute

Derived Attribute

E1 R E2
Total Participation

1 N
E1 R E2 Cardinality
Enhanced Entity Relationship (EER):

1. Generalization:
Generalization is a bottom-up approach in which two lower level
entities combine to form a higher level entity.
Account

ISA

Saving Current

2. Specialization:

It is a process of defining subclasses of an entity type; this entity type is


called the super class of the specialization.
For example: the set of subclasses {secretary, engineer, technician} is
the specialization of the super class employee.
Specialization allows to do:
a. Define a set of subclasses of an entity type.
b. Establish additional specific attributes with each subclass.
c. Establish additional specific relationship types between each

subclass and other entity types or other subclass.

Staff

ISA

Teaching Non-Teaching
3. Aggregation:

Aggregation is an abstraction through which relationships are treated as


higher-level entities.

COMPANY IN APPLICANT
COMPANY INT APPLICANT

RES JOB_OFFER

Conclusion: The ER and EER for the given problem statement is studied and drawn
EXPERIMENT NO : 2

AIM-

perform mapping ER/EER to relational schema model

THEORY:

Step 1 : Mapping of Regular Entity Types :

For each regular(strong) entity type E in the ER schema create a relation R


that includes all the simple attributes of E. Include only the simple component
attributes of a composite ,the set of simple attributes that form it will together form
the primary key of R.
If multiple keys were identified for E during the conceptual design, the
information describing the attributes that form each additional key is kept in order
to specify secondary(unique) keys of relation R.
For example : SUPERNO and DNO will be attribute of employee and
MGRENO and MGRSTARTDATE will be attribute of department and DNUM of
project.

Step 2: Mapping of Weak Entity Types :

For each weak entity type W in the ER schema with owner entity type E,
create a relation R and include all simple attributes(or simple component of
composite attributes)of W as attributes of R.In addition include as foreign key
attributes of R the Primary key attribute(s) of the relation(s) that correspond to the
owner entity type(s); this takes care of the identifying relationship type of W. The
primary key of R is the combination of the primary key(s) of the owner(s) and the
partial key of the Weak Entity Type W, if any.
If there is a weak entity type E2, whose owner is also a weak entity type
E1, should be mapped before E2 to determine its primary key first.
For Example : We create the relation DEPENDENT to correspond to the
weak entity type DEPENDENT. We include the primary key ENO as a foreign key
attribute of DEPENDENT; we renamed it EENO, although this is not
necessary.Theprimary key of the DEPENDENT relation is combination {EENO,
DEPENDENT NAME} because DEPENDENT_NAME is the partial key of
DEPENDENT.
Step 3 : Mapping of Binary 1:1 Relationship Types :

For each binary 1:1 relationship type R in the ER schema, identify the
relations S and T that correspond to the Entity Types participating in R. There are
three possible approaches given below.

1. Foreign key approach : Choose one of the relations- S, say – and include as
a Foreign key in S the primary key of T. It is better to choose an entity type
with total participation in R in the role of S.Include all the simple attributes
(or simple components of a composite attributes) of the 1:1 relationship type
R as attributes of S.

For example: we map the 1:1 relationship type MANAGES, by choosing the
participating entity type DEPARTMENT to serve in the role of S, because its
participation in the MANAGES relationship type is total(every department has a
manager). We include the includes all the simple attributes Primary key of the
EMPLOYEE relation as foreign key in the DEPARTMENT relation and rename it
MGRENO. We also include the simple attribute STARTDATE of the MANAGES
relationship type in the DEPARTMENT relation and rename it MGRSTARTDATE.

NOTE: It is possible to include the primary key of S as a foreign key in T instead.


In our example, this amounts to having a Foreign key attribute, say
DEPARTMENT_MANAGED in the EMPLOYEE relation, but it will have a null
value for EMPLOYEE tuples who do not manage a department. If only 10 percent
of employees manage a department , then 90 percent of the foreign keys would be
null in this case.

2. Merged relation option : An alternative mapping of a 1:1 relationship type


is possible by merging the two entity types and the relationship into a single
relation. This may be appropriate when both participations are total.
3. Cross-reference or relationship relation option : The third alternative is to
set up a third relation R for yhe purpose of cross-referencing the primary
keys of the two relations S and T representing the entity types.
Step 4 : Mapping of Binary 1:N Relationship Types :

For each regular binary 1:N relationship type R, identifying the relation S
that represent the participating Entity Type at the N side of the relationship type.
Include as Foreign key in S the primary key of T that represents the other entity
type participating in R; this is done because each entity instance on the N side is
related to at most one entity instance on the 1-side of the relationship Type. Include
any simple attributes (or simple components of composite attributes) of the 1:N
relationship type as attributes of S.

For example : In our example, we map the 1:N relationship types


WORKS_FOR,CONTROLS, and SUPERVISION from fig. For WORKS_FOR
we include the PRIMARY KEY DNUMBER of the DEPARTMENT relation as
foreign key in the EMPLOYEE relation and call it DNO. For SUPERVISION we
include the primary key of the EMPLOYEE relation as foreign key in the
EMPLOYEE relation itself because the relationship is recursive- and call it
SUPERNO. The CONTROLS relationship is mapped to the foreign key attribute
DNUM of PROJECT, which references the primary key DNUMBER of the
DEPARTMENT relation.

Step 5 : Mapping of Binary M:N Relationship Types :

For each binary M:N relationship type R, create a new relation S to


represent R. Include as Foreign key attributes in S the primary key of the relations
that represent the participating entity types; their combination will form the
primary key of S. Also include any simple attributes of the M:N relationship types
(or simple components of a composite attributes) as attributes of S. Notice that we
cannot represent an M:N relationship type by a single Foreign key attribute in one
of the participating relations (aswe did for 1:1 or 1:N relationship types) because of
the M:N cardinality ratio; we must create a separate relationship relation S.

For example : we map the M:N Relationship type WORKS_ON from fig by
creating the relation WORKS_ON in fig. We include the primary keys of the
PROJECT and EMPLOYEE relations
as Foreign keys in WORKS_ON and rename them PNO and EENO,respectively.
We also include an attribute HOURS in WORKS_ON to represent the HOURS
attribute of the relationship type. The primary key of the WORKS_ON relation is
the combination of the foreign key attributes {EENO,PNO}

Step 6: Mapping of Multivalued Attributes :

For each Multivalued Attribute A, create a new relation R.This relation R


will include an attribute corresponding to A, plus the primary key attribute K- as a
foreign key in R- of the relation that represents the entity type or relationship type
that has A as an attribute. The primary key of R is the combination of A and K. If
the multivalued attribute is composite, we include its simple components.

Step 7: Mapping of N-ary Relationship Types :

For each N-ary relationship type R, where N>2, create a new relation S to
represent R. Include as Foreign key attributes in S the primary keys of the relations
that represent the participating entity types. Also include any simple attributes of
the N-ary relationship types (or simple components of a composite attributes) as
attributes of S. . The primary key of S is usually a combination of all the foreign
keys that reference the relations representing the participating entity types.
However, if the cardinality constraints on any of the entity types E participating in
R is 1, then the primary key of S should not include the foreign key attribute that
references the relation E’ corresponding to E is composite, we include its simple
components.
For example: primary key of SUPPLIER relation is SNAME, primary key of
PROJECT relation is PROJNAME ,primary key of PART relation is PARTNO,
then primary key of SUPPLY relation is the combination of the three Foreign keys
{SNAME, PROJNAME, PARTNO}.

Correspondence between ER and Relational Models

ER Models Relational Models

1:1 or 1: N Relationship Type Foreign key(or “relationship” relation)

M :N Relationship Type “Relationship” relation & two foreign keys


N -ary Relationship Types “Relationship” relation & N foreign keys

Simple attribute Attribute

Composite attribute Set of simple Component

attributes Multivalued Attribute Relation and Foreign Key.

Conclusion:

Referring to the problem statement the ER diagram was designed and converted into
the tables.
EXPERIMENT NO-3

AIM-Write Data Definition Language (DDL) and DML Commands to


populate database for the given specified System.

THEORY SQL - SQL is a short-form of the structured query language,


and it is pronounced as S-Q-L or sometimes as See-Quell.This database
language is mainly designed for maintaining the data in relational
database management systems. It is a special tool used by data
professionals for handling structured data (data which is stored in the
form of tables). It is also designed for stream processing in RDSMS.
DDL Commands in SQL.

DDL is an abbreviation of Data Definition Language.

The DDL Commands in Structured Query Language are used to create


and modify the schema of the database and its objects. The syntax of
DDL commands is predefined for describing the data. The commands of
Data Definition Language deal with how the data should exist in the
database.

Following are the five DDL commands in SQL:

1. CREATE Command
2. DROP Command
3. ALTER Command
4. TRUNCATE Command
5. RENAME Command

CREATE Command

CREATE is a DDL command used to create databases, tables, triggers


and other database objects.

Syntax to Create a Database:

CREATE Database Database_Name;

DROP Command
DROP is a DDL command used to delete/remove the database objects
from the SQL database. We can easily remove the entire table, view, or
index from the database using this DDL command.

Syntax to remove a database:

DROP DATABASE Database_Name;

ALTER Command

ALTER is a DDL command which changes or modifies the existing


structure of the database, and it also changes the schema of database
objects.We can also add and drop constraints of the table using the
ALTER command.

Syntax to add a newfield in the table:

ALTER TABLE name_of_table ADD column_name column_definition;

Syntax to remove a column from the table:

ALTER TABLE name_of_table DROP Column_Name_1 , column_Nam


e_2 , ….., column_Name_N;

Syntax to modify the column of the table:

ALTER TABLE table_name MODIFY ( column_name column_datatype


(size));

TRUNCATE Command

TRUNCATE is another DDL command which deletes or removes all the


records from the table.This command also removes the space allocated
for storing the table records.

Syntax of TRUNCATE command

TRUNCATE TABLE Table_Name;

RENAME Command

RENAME is a DDL command which is used to change the name of the


database table.
Syntax of RENAME command

RENAME TABLE Old_Table_Name TO New_Table_Name;

CONCLUSION
Implemented various DDL and DML command and also applied various
constraints on the table.
EXPERIMENT NO.-4

AIM-Write Integrity Constraints for the specified system.


THEORY-
Integrity Constraints

o Integrity constraints are a set of rules. It is used to maintain the


quality of information.
o Integrity constraints ensure that the data insertion, updating, and
other processes have to be performed in such a way that data
integrity is not affected.
o Thus, integrity constraint is used to guard against accidental
damage to the database.

Types of Integrity Constraint

There are four types of integrity constraints in DBMS:

1. Domain Constraint
2. Entity Constraint
3. Referential Integrity Constraint
4. Key Constraint

1. Domain constraints

o Domain constraints can be defined as the definition of a valid set of


values for an attribute.
o The data type of domain includes string, character, integer, time,
date, currency, etc. The value of the attribute must be available in
the corresponding domain.

Example:
Syntax
CREATE TABLE table_name (column1 datatype constraint,column2
datatype constraint,column3 datatype constraint, ....);

2. Entity integrity constraints

o The entity integrity constraint states that primary key value can't be
null.
o This is because the primary key value is used to identify individual
rows in relation and if the primary key has a null value, then we
can't identify those rows.
o A table can contain a null value other than the primary key field.

Syntax:

CREATE TABLE Persons (ID int NOT NULL,LastName


varchar(255)NOTNULL,FirstNamevarchar(255),Ageint PRIMARY K
EY (ID));

Example

3. Referential Integrity Constraints


o A referential integrity constraint is specified between two tables.
o In the Referential integrity constraints, if a foreign key in Table 1
refers to the Primary Key of Table 2, then every value of the
Foreign Key in Table 1 must be null or be available in Table 2.

Example:

Systax:

CREATE TABLE Orders ( OrderID int NOT NULL,OrderNumber


int NOT NULL,PersonID int, PRIMARY KEY (OrderID),
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)
);

4. Key constraints

o Keys are the entity set that is used to identify an entity within its
entity set uniquely.
o An entity set can have multiple keys, but out of which one key will
be the primary key. A primary key can contain a unique and null
value in the relational table.

Example:
35.5M
824
OOPs Concepts in Java

Syntax:

CREATE TABLE Persons (


ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
PRIMARY KEY (ID)
);
A check constraint

It is a type of integrity constraint in SQL which specifies a requirement


that must be met by each row in a database table. The constraint must be
a predicate. It can refer to a single column, or multiple columns of the
table. The result of the predicate can be either TRUE, FALSE,
or UNKNOWN, depending on the presence of NULLs. If the predicate
evaluates to UNKNOWN, then the constraint is not violated and the row
can be inserted or updated in the table. This is contrary to predicates
in WHERE clauses in SELECT or UPDATE statements.
For example, in a table containing products, one could add a check
constraint such that the price of a product and quantity of a product is a
non-negative value:
PRICE >= 0
QUANTITY >= 0
If these constraints were not in place, it would be possible to have a
negative price (−$30) or quantity (−3 items).
Check constraints are used to ensure the validity of data in a database and
to provide data integrity. If they are used at the database level,
applications that use the database will not be able to add invalid data or
modify valid data so the data becomes invalid, even if the application
itself accepts invalid data.

Definition
Each check constraint has to be defined in the CREATE
TABLE or ALTER TABLE statement using the syntax:
CREATE TABLE table_name (
...,
CONSTRAINT constraint_name CHECK ( predicate ),
...
)
ALTER TABLE table_name
ADD CONSTRAINT constraint_name CHECK ( predicate )
If the check constraint refers to a single column only, it is possible to
specify the constraint as part of the column definition.
CREATE TABLE table_name (
...
column_name type CHECK ( predicate ),
...
)
NOT NULL constraint
A NOT NULL constraint is functionally equivalent to the following
check constraint with an IS NOT NULL predicate:
CHECK (column IS NOT NULL)
Some relational database management systems are able to optimize
performance when the NOT NULL constraint syntax is used as opposed
to the CHECK constraint syntax given above.

CONCLUSION:
Various constraint can be applied on the table for better design and as per
the requirement of the user.
EXPERIMENT NO.-5

AIM-Write Simple queries, string manipulation operations for the given


statement of problem.

THEORY-string functions manipulate the character string data


effectively. The following table indicates each of the functions with a
brief description.
SELECT -The SQL SELECT Statement
The SELECT statement is used to select data from a database.
The data returned is stored in a result table, called the result-set.
SELECT Syntax
SELECT column1, column2, ...
FROM table_name;
Here, column1, column2, ... are the field names of the table you want to
select data from. If you want to select all the fields available in the table,
use the following syntax:
SELECT * FROM table_name;
WHERE
The SQL WHERE Clause
The WHERE clause is used to filter records.
It is used to extract only those records that fulfill a specified condition.
WHERE Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition;
The WHERE clause is not only used in SELECT statements, it is also used
in UPDATE, DELETE, etc.!
GROUP BY

The SQL GROUP BY Statement


The GROUP BY statement groups rows that have the same values into
summary rows, like "find the number of customers in each country".
The GROUP BY statement is often used with aggregate functions
(COUNT(), MAX(), MIN(), SUM(), AVG()) to group the result-set by
one or more columns.
GROUP BY Syntax
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);
The following SQL statement lists the number of customers in each
country:

Example

SELECT COUNT(CustomerID), Country


FROM Customers
GROUP BY Country;
HAVING Clause
The HAVING clause was added to SQL because the WHERE keyword
cannot be used with aggregate functions.
HAVING Syntax
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
SQL HAVING Examples
The following SQL statement lists the number of customers in each
country. Only include countries with more than 5 customers:

Example
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5;
ORDER BY
The SQL ORDER BY Keyword
The ORDER BY keyword is used to sort the result-set in ascending or
descending order.
The ORDER BY keyword sorts the records in ascending order by default.
To sort the records in descending order, use the DESC keyword.
ORDER BY Syntax
SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;

ORDER BY Example
The following SQL statement selects all customers from the "Customers"
table, sorted by the "Country" column:

Example

SELECT * FROM Customers


ORDER BY Country;
The following SQL statement lists the number of customers in each
country, sorted high to low:

Example

SELECT COUNT(CustomerID), Country


FROM Customers
GROUP BY Country
ORDER BY COUNT(CustomerID) DESC;.

CONCLUSION-
Thus we have design the queries of simple and string manipulation operations
EXPERIMENT NO.6

AIM-Write Nested queries and Complex queries for the given statement of
problem.
THEORY-
Nested Queries -In nested queries, a query is written inside a query. The result
of inner query is used in execution of outer query. We will use STUDENT,
COURSE, STUDENT_COURSE tables for understanding nested queries.

STUDENT

S_ID S_NAME S_ADDRESS S_PHONE S_AGE

S1 RAM DELHI 9455123451 18

S2 RAMESH GURGAON 9652431543 18

S3 SUJIT ROHTAK 9156253131 20

S4 SURESH DELHI 9156768971 18

COURSE

C_ID C_NAME

C1 DSA

C2 Programming

C3 DBMS
STUDENT_COURSE

S_ID C_ID

S1 C1

S1 C3

S2 C1

S3 C2

S4 C2

S4 C3
There are mainly two types of nested queries:
Independent Nested Queries: In independent nested queries, query
execution starts from innermost query to outermost queries. The execution
of inner query is independent of outer query, but the result of inner query
is used in execution of outer query. Various operators like IN, NOT IN,
ANY, ALL etc are used in writing independent nested queries.

IN: If we want to find out S_ID who are enrolled in C_NAME ‘DSA’ or
‘DBMS’, we can write it with the help of independent nested query and
IN operator. From COURSE table, we can find
out C_ID for C_NAME ‘DSA’ or DBMS’ and we can use these C_IDs
for finding S_IDs from STUDENT_COURSE TABLE.
STEP 1: Finding C_ID for C_NAME =’DSA’ or ‘DBMS’
Select C_ID from COURSE where C_NAME = ‘DSA’ or C_NAME =
‘DBMS’
STEP 2: Using C_ID of step 1 for finding S_ID
Select S_ID from STUDENT_COURSE where C_ID IN
(SELECT C_ID from COURSE where C_NAME = ‘DSA’
or C_NAME=’DBMS’);
The inner query will return a set with members C1 and C3 and outer
query will return those S_IDs for which C_ID is equal to any member of
set (C1 and C3 in this case). So, it will return S1, S2 and S4.

Note: If we want to find out names of STUDENTs who have either


enrolled in ‘DSA’ or ‘DBMS’, it can be done as:
Select S_NAME from STUDENT where S_ID IN
(Select S_ID from STUDENT_COURSE where C_ID IN
(SELECT C_ID from COURSE where C_NAME=’DSA’
or C_NAME=’DBMS’));

NOT IN: If we want to find out S_IDs of STUDENTs who have neither
enrolled in ‘DSA’ nor in ‘DBMS’, it can be done as:
Select S_ID from STUDENT where S_ID NOT IN
(Select S_ID from STUDENT_COURSE where C_ID IN
(SELECT C_ID from COURSE where C_NAME=’DSA’
or C_NAME=’DBMS’));
The innermost query will return a set with members C1 and C3. Second
inner query will return those S_IDs for which C_ID is equal to any
member of set (C1 and C3 in this case) which are S1, S2 and S4. The
outermost query will return those S_IDs where S_ID is not a member of
set (S1, S2 and S4). So it will return S3.

Co-related Nested Queries: In co-related nested queries, the output of


inner query depends on the row which is being currently executed in
outer query. e.g.; If we want to find out S_NAME of STUDENTs who
are enrolled in C_ID ‘C1’, it can be done with the help of co-related
nested query as:
Select S_NAME from STUDENT S where EXISTS
( select * from STUDENT_COURSE SC where S.S_ID=SC.S_ID and
SC.C_ID=’C1’);

For each row of STUDENT S, it will find the rows


from STUDENT_COURSE where S.S_ID = SC.S_ID and
SC.C_ID=’C1’. If for a S_ID from STUDENT S, atleast a row exists
in STUDENT_COURSE SC with C_ID=’C1’, then inner query will
return true and corresponding S_ID will be returned as output.The inner
query will return a set with members C1 and C3 and outer query will
return those S_IDs for which C_ID is equal to any member of set (C1 and
C3 in this case). So, it will return S1, S2 and S4.
Note: If we want to find out names of STUDENTs who have either
enrolled in ‘DSA’ or ‘DBMS’, it can be done as:
Select S_NAME from STUDENT where S_ID IN
(Select S_ID from STUDENT_COURSE where C_ID IN
(SELECT C_ID from COURSE where C_NAME=’DSA’
or C_NAME=’DBMS’));
NOT IN: If we want to find out S_IDs of STUDENTs who have neither
enrolled in ‘DSA’ nor in ‘DBMS’, it can be done as:
Select S_ID from STUDENT where S_ID NOT IN
(Select S_ID from STUDENT_COURSE where C_ID IN
(SELECT C_ID from COURSE where C_NAME=’DSA’
or C_NAME=’DBMS’));

CONCLUSION-
Implemented various nested and complex queris and executed
successfully

.
EXPERIMENT NO.-7

AIM-Perform Join operations for the given statement of problem.

THEORY- SQL:JOINS

Description
SQL JOINS are used to retrieve data from multiple tables. A SQL JOIN
is performed whenever two or more tables are listed in a SQL statement.
There are 4 different types of SQL joins:

 SQL INNER JOIN (sometimes called simple join)


 SQL LEFT OUTER JOIN (sometimes called LEFT JOIN)
 SQL RIGHT OUTER JOIN (sometimes called RIGHT JOIN)
 SQL FULL OUTER JOIN (sometimes called FULL JOIN)

Sample Table-EMPLOYEE

EMP_ID EMP_NAME CITY SALARY AGE

1 Angelina Chicago 200000 30


2 Robert Austin 300000 26
3 Christian Denver 100000 42
4 Kristen Washington 500000 29
5 Russell Los angels 200000 36
6 Marry Canada 600000 48

PROJECT

PROJECT_NO EMP_ID DEPARTMENT

101 1 Testing
102 2 Development
103 3 Designing
104 4 Development
1. INNER JOIN

In SQL, INNER JOIN selects records that have matching values in both
tables as long as the condition is satisfied. It returns the combination of
all rows from both the tables where the condition satisfies.It is the most
common type of SQL join. SQL INNER JOINS return all rows from
multiple tables where the join condition is met.

Syntax

1. SELECT table1.column1, table1.column2, table2.column1,....


2. FROM table1
3. INNER JOIN table2
4. ON table1.matching_column = table2.matching_column;

Query

1. SELECT EMPLOYEE.EMP_NAME, PROJECT.DEPARTMENT

2. FROM EMPLOYEE
3. INNER JOIN PROJECT
4. ON PROJECT.EMP_ID = EMPLOYEE.EMP_ID;

Output

EMP_NAME DEPARTMENT

Angelina Testing
Robert Development
Christian Designing
Kristen Development

2. LEFT JOIN

The SQL left join returns all the values from left table and the matching
values from the right table. If there is no matching join value, it will
return NULL.This type of join returns all rows from the LEFT-hand table
specified in the ON condition and only those rows from the other table
where the joined fields are equal (join condition is met).
Syntax

1. SELECT table1.column1, table1.column2, table2.column1,....


2. FROM table1
3. LEFT JOIN table2
4. ON table1.matching_column = table2.matching_column;

Query

1. SELECT EMPLOYEE.EMP_NAME, PROJECT.DEPARTMENT

2. FROM EMPLOYEE
3. LEFT JOIN PROJECT
4. ON PROJECT.EMP_ID = EMPLOYEE.EMP_ID;

Output

EMP_NAME DEPARTMENT

Angelina Testing
Robert Development
Christian Designing
Kristen Development
Russell NULL
Marry NULL

3. RIGHT JOIN

In SQL, RIGHT JOIN returns all the values from the values from the
rows of right table and the matched values from the left table. If there is
no matching in both tables, it will return NULL.This type of join returns
all rows from the RIGHT-hand table specified in the ON condition
and only those rows from the other table where the joined fields are equal
(join condition is met).

Syntax
1. SELECT table1.column1, table1.column2, table2.column1,....
2. FROM table1
3. RIGHT JOIN table2
4. ON table1.matching_column = table2.matching_column;

Query

1. SELECT EMPLOYEE.EMP_NAME, PROJECT.DEPARTMENT

2. FROM EMPLOYEE
3. RIGHT JOIN PROJECT
4. ON PROJECT.EMP_ID = EMPLOYEE.EMP_ID;

Output

EMP_NAME DEPARTMENT

Angelina Testing
Robert Development
Christian Designing
Kristen Development

4. FULL JOIN

In SQL, FULL JOIN is the result of a combination of both left and right
outer join. Join tables have all the records from both tables. It puts NULL
on the place of matches not found. This type of join returns all rows from
the RIGHT-hand table specified in the ON condition and only those rows
from the other table where the joined fields are equal (join condition is
met).

Syntax

1. SELECT table1.column1, table1.column2, table2.column1,....


2. FROM table1
3. FULL JOIN table2
4. ON table1.matching_column = table2.matching_column;

Query

1. SELECT EMPLOYEE.EMP_NAME, PROJECT.DEPARTMENT

2. FROM EMPLOYEE
3. FULL JOIN PROJECT
4. ON PROJECT.EMP_ID = EMPLOYEE.EMP_ID;

Output

EMP_NAME DEPARTMENT

Angelina Testing
Robert Development
Christian Designing
Kristen Development
Russell NULL
Marry NULL

CONCLUSION-
Implemented various nested and complex queris and executed successfully.
Experiment No. 08

Aim: Write Views and Triggers for the given statement of problem.
Theory:
Concept of a View:
A view in SQL terminology is a single table that is derived from other
tables. These other tables could be base tables or previously defined
views. A view does not necessarily exist in physical form; it is considered
a virtual table, in contrast to base tables whose tuples are actually stored
in the database. This limits the possible update operations that can be
applied to views, but it does not provide any limitations on querying a
view.
Specification of Views:
The command to specify a view is CREATE VIEW. The view is given a
(virtual) table name (or view name), a list of attribute names, and a query
to specify the contents of the view. If none of the view attributes result
from applying functions or arithmetic operations, we do not have to
specify attribute names for the view, as they would be the same as the
names of the attributes of the defining tables in the default case.
Syntax:
CREATE VIEW <view name>[ (<column name> { , <column
name> } ) ]
AS <SELECT statement>;
Querying View:
We can now specify SQL queries on a view or virtual table in the same
way we specify queries involving base tables.
Updating View:
A view is always up to date; if we modify the tuples in the base tables on
which the view is defined, the view must automatically reflect these
changes. Hence, the view is not realized at the time of view definition but
rather at the time we specify a query on the view. It is the responsibility
of the DBMS and not the user to make sure that the view is up to date.
Updating of views is complicated and can be ambiguous. In general, an
update on a view defined on a single table without any aggregate
functions can be mapped to an update on the underlying base
table.Dropping View: If we do not need a view any more, we can use the
DROP VIEW command to dispose of it.
Syntax:
DROP VIEW <view name>;
Advantages:
● View simplifies the specification of certain queries.
● Views are used as a security and authorization mechanism.
Concept of Trigger:
A database triggers is stored PL/SQL program unit associated with a
specific database table or view. The code in the trigger defines the action
the database needs to perform whenever some database manipulation
(INSERT, UPDATE, and DELETE) takes place. Unlike the stored
procedure and functions, which have to be called explicitly, the database
triggers are fired (executed) or called implicitly whenever the table is
affected by any of the above said DML operations. Till oracle 7.0 only 12
triggers could be associated with a given table, but in higher versions of
Oracle there is no such limitation. A database trigger fires with the
privileges of owner not that of user
A database trigger has three parts
1. A triggering event
2. A trigger constraint (Optional)
3. Trigger action
A triggering event can be an insert, update, or delete statement or a
instance shutdown or startup etc. The trigger fires automatically when
any of these events occur on the specified table or a view. A trigger
constraint specifies a Boolean expression that must be true for the trigger
to fire. This condition is specified using the WHEN clause. The trigger
action is a procedure that contains the code to be executed when the
trigger fires.
Syntax:
BEFORE INSERT Trigger
A BEFORE INSERT Trigger means that Oracle will fire this trigger
before the INSERT operation is executed.
CREATE or REPLACE TRIGGER trigger_name
BEFORE INSERT ON table_name
[ FOR EACH ROW ]
DECLARE
-- variable declarationsBEGIN
-- trigger code
EXCEPTION
WHEN ...
-- exception handling
END;
trigger_name is the name of the trigger to create.
Restrictions:
● One can not create a BEFORE trigger on a view.
● One can update the :NEW values.
● One can not update the :OLD values.
AFTER INSERT Trigger
An AFTER INSERT Trigger means that Oracle will fire this trigger after
the INSERT operation
is executed.
The syntax for an AFTER INSERT Trigger is:
CREATE or REPLACE TRIGGER trigger_name
AFTER INSERT
ON table_name
[ FOR EACH ROW ]
DECLARE
-- variable declarations
BEGIN
-- trigger code
EXCEPTION
WHEN ...
-- exception handling
END;
trigger_name is the name of the trigger to create.
AFTER UPDATE Trigger
An AFTER UPDATE Trigger means that Oracle will fire this trigger
after the UPDATE
operation is executed.
The syntax for an AFTER UPDATE Trigger is:
CREATE or REPLACE TRIGGER trigger_name
AFTER UPDATE
ON table_name
[ FOR EACH ROW ]
DECLARE
-- variable declarationsBEGIN
-- trigger code
EXCEPTION
WHEN ...
-- exception handling
END;
trigger_name is the name of the trigger to create.
Drop a Trigger
The syntax for a dropping a Trigger is:
DROP TRIGGER trigger_name;
Disable a Trigger
The syntax for a disabling a Trigger is:
ALTER TRIGGER trigger_name DISABLE;
Enable a Trigger
The syntax for a enabling a Trigger is:
ALTER TRIGGER trigger_name ENABLE;
Conclusion:
● A view with a single defining table is updatable if the view attributes
contain the primary key (or possibly some other candidate key) of the
base relation, because this maps each (virtual) view tuple to a single base
tuple.
● Views defined on multiple tables using joins are generally notupdatable.
● Views defined using grouping and aggregate functions are notupdatable.
● Trigger generates some derived column values automatically also
enforces referential integrity
Experiment No. 09

Aim : Write Functions and procedure for the given statement of problem.
Theory :
Procedure is a subprogram used to perform a specific action. A
subprogram is a named block of PL/SQL. There are two types of
subprograms in PL/SQL namely Procedures and Functions. Every
subprogram will have a declarative part, an executable part or body, and
an exception handling part, which is optional. Declarative part contains
variable declarations. Body of a subprogram contains executable
statements of SQL and PL/SQL. Statements to handle exceptions are
written in exception part.Procedure specification begins with CREATE
and ends with procedure name or parameters list. Procedures that do not
take parameters are written without a parenthesis. The body of the
procedure starts after the keyword IS or AS and ends with keyword END.
Syntax for Procedure:
CREATE [OR REPLACE] PROCEDURE procedure_name
[(parameter_name [IN | OUT | IN OUT] type [, ...])]
{IS | AS}
BEGIN
procedure_body
EXCEPTION
Exception handling
END procedure_name;
Procedure is created using CREATE PROCEDURE statement.
OR REPLACE specifies the procedure is to replace an existing
procedure if present. One can use this option to modify an existing
procedure.A procedure may be passed multiple parameters. IN | OUT |
IN OUT specifies the mode of the parameter. Type specifies the datatype
of the parameter.
IN - The parameter can be referenced by the procedure or function. The
value of the parameter cannot be overwritten by the procedure or function.
OUT - The parameter cannot be referenced by the procedure or function,
but the value of the parameter can be overwritten by the procedure or
function.
IN OUT - The parameter can be referenced by the procedure or function
and the value of the parameter can be overwritten by the procedure or
function.Procedure body contains the SQL and PL/SQL statements to
perform the procedure's task.Exception Section:The Exception section of
a PL/SQL Block starts with the reserved keyword EXCEPTION. This
section is optional. Any errors in the program can be handled in this
section,
so that the PL/SQL Blocks terminates gracefully. If the PL/SQL Block
contains exceptions that cannot be handled, the Block terminates abruptly
with errors.
Advantages:
When client executes a procedure or a function, the processing is done in
the server.Server is likely to me more powerful than the clients which in
turn mean that stored procedures should run faster. This reduces network
traffic.As the procedures/functions are stored in the Oracle database there
is no need to transfer the code from the clients to the database server or to
transfer intermediate results from the server to the clients. This results in
much less network traffic and again improves scalability The
subprograms are compiled and stored in the Oracle database as stored
programs and can be invoked whenever required. As they are stored in
compiled form when called, they only need to be executed. Hence they
save time needed for compilation. They allow breaking the program into
manageable modules. They provide reusability and maintainability for the
code.
Disadvantages:
There is an overhead involved in embedding or calling PL/SQL
procedures from SQL in Oracle due to the context switching that the
Oracle database has to perform. This may be significant in terms of
performance but usually this overhead is outweighed by performance
advantages of using PL/SQL. More memory may be required on the
Oracle database server when using Oracle PL/SQL packages as the whole
package is loaded into memory as soon as any object in the package is
Accessed A function is a named PL/SQL Block which is similar to a
procedure. The major difference between a procedure and a function is, a
function must always return a value, but a procedure may or may not
return a value.
Syntax for Function:
CREATE [OR REPLACE] FUNCTION function_name [parameters]
RETURN return_datatype;
IS
Declaration_section
BEGIN
Execution_section
Return return_variable;
EXCEPTION
exception section
Return return_variable; END;
Return Type:
The header section defines the return type of the function. The return
datatype can be any of the oracle datatype like varchar, number etc. The
execution and exception section both should return a value which is of the
datatype defined in the header section.

Conclusion:
Stored procedures should be used to improve the performance and
scalability of applications. The disadvantages are easily outweighed by
the advantages and the use of packages to combine related objects
(procedures, functions and variables) into one physical unit enhances
these advantages. Functions are PL/SQL stored programming units,
providing a way to hide implementation details in a programming unit.
Functions can be used as right operands in PL/SQL and be called from
SQL statements, while procedures cannot.
EXPERIMENT NO.-10

AIM-Perform Transaction and Concurrency control for the given


statement of problem.
THEORY-
transaction
A transaction is a unit of operations, usually read and write operations,
which is executed from start to finish to access and update various data
items. An example is transferring money from a savings account to a
checking account.
It is an action or sequence of actions passed out by a single user and/or
application program that reads or updates the contents of the database. A
transaction is a logical piece of work of any database, which may be a
complete program, a fraction of a program, or a single command (like the:
SQL command INSERT or UPDATE) that may involve any number of
processes on the database. From the database point of view, the
implementation of an application program can be considered as one or
more transactions with non-database processing working in between.

TCL Commands
1. COMMIT
This command is used to make a transaction permanent in a database. So
it can be said that commit command saves the work done as it ends the
current transaction by making permanent changes during the transaction.
The syntax for this command is as below.
COMMIT;
For instance, we want to update the location of an employee in the table
“EMPLOYEE”. Sample EMPLOYEE table is given below:

EMP_ID EMP_NAME EMP_LOC


1356 Raju Delhi
2678 Neeta Bangalore
9899 Sanjay Hyderabad
Let us update the EMP_ LOC for Raju as below:
Query:
UPDATE EMPLOYEE SET EMP_ LOC = 'Hyderabad' WHERE
EMP_NAME= 'Raju';
COMMIT;
The update transaction is completed with the commit command as above
and the usage of the above statements will update the location of the
employee ‘Raju’ and the change will be saved in the database
permanently.
The updated table is as shown below:
EMP_ID EMP_NAME EMP_LOC
1356 Raju Hyderabad
2678 Neeta Bangalore
9899 Sanjay Hyderabad
2. ROLLBACK
This command is used to restore the database to its original state since the
last command that was committed. The syntax of the Rollback command
is as below:

ROLLBACK;
Also, the ROLLBACK command is used along with savepoint command
to leap to a save point in a transaction. The syntax for the same is as
below:
ROLLBACK TO <savepoint_name>;
Let us take the example of the EMPLOYEE table as cited above. Let us
consider that we have updated EMP_LOC for Raju to Bangalore later and
realize that the update was done mistakenly as below. Then we can
restore the EMP_LOC for ‘Raju’ to Hyderabad again by using the
Rollback command as below.
Query:
UPDATE EMPLOYEE SET EMP_LOC= 'Bangalore' WHERE
EMP_NAME = 'Raju';
ROLLBACK;
After the wrong update the table is as below:

EMP_ID EMP_NAME EMP_LOC


1356 Raju Bangalore
2678 Neeta Bangalore
9899 Sanjay Hyderabad
After the Rollback is performed, the location for Raju is restored to the
last committed state as shown below.
EMP_ID EMP_NAME EMP_LOC
1356 Raju Hyderabad
2678 Neeta Bangalore
9899 Sanjay Hyderabad
3. SAVEPOINT
This command is used to save the transaction temporarily. So the users
can rollback to the required point of the transaction. The syntax for using
this command is as below:
SAVEPOINT savepoint_name;
Let us take the example of a table “ORDERS” with columns as
ORDER_ID and ITEM_NAME.
ORDER_ID ITEM_NAME
199 TELEVISION
290 CAMERA
Let us insert the below values to the ORDERS table below and perform
the updates using savepoint.
Query:
INSERT INTO ORDERS VALUES ('355' , 'CELL PHONE');
COMMIT;
UPDATE ORDERS SET ITEM_NAME = 'SMART PHONE' WHERE
ORDER_ID= '355';
SAVEPOINT A;
INSERT INTO ORDERS VALUES ('566' , 'BLENDER');
SAVEPOINT B;
Now the ORDERS table will be as below:

Now the ORDERS table will be as below:


ORDER_ID ITEM_NAME
199 TELEVISION
290 CAMERA
355 SMART PHONE
566 BLENDER
Now we can use the SAVEPOINT command to Rollback the transaction.
Let us Rollback the transaction to savepoint A.
Query:
ROLLBACK TO A;
The ORDERS table will be as below:
ORDER_ID ITEM_NAME
199 TELEVISION
290 CAMERA
355 SMART PHONE

4. SET TRANSACTION
 SET TRANSACTION is used for placing a name on a transaction.

Syntax:

SET TRANSACTION (READ WRITE/READ ONLY)

 You can specify a transaction to be read only or read write.


 This command is used to initiate a database transaction.

Concurrency Control

Concurrency Control is the working concept that is required for


controlling and managing the concurrent execution of database operations
and thus avoiding the inconsistencies in the database. Thus, for
maintaining the concurrency of the database, we have the concurrency
control protocols.

Concurrency Control Protocols

The concurrency control protocols ensure the atomicity, consistency,


isolation, durability and serializability of the concurrent execution of the
database transactions. Therefore, these protocols are categorized as:

o Lock Based Concurrency Control Protocol


o Time Stamp Concurrency Control Protocol

Lock-Based Protocol
In this type of protocol, any transaction cannot read or write data until it
acquires an appropriate lock on it. There are two types of lock:

1. Shared lock:

o It is also known as a Read-only lock. In a shared lock, the data item


can only read by the transaction.
o It can be shared between the transactions because when the
transaction holds a lock, then it can't update the data on the data
item.

2. Exclusive lock:

o In the exclusive lock, the data item can be both reads as well as
written by the transaction.
o This lock is exclusive, and in this lock, multiple transactions do not
modify the same data simultaneously.

Timestamp-based Protocols
Timestamp based Protocol in DBMS is an algorithm which uses the
System Time or Logical Counter as a timestamp to serialize the execution
of concurrent transactions. The Timestamp-based protocol ensures that
every conflicting read and write operations are executed in a timestamp
order.
The older transaction is always given priority in this method. It uses
system time to determine the time stamp of the transaction. This is the
most commonly used concurrency protocol.

Lock-based protocols help you to manage the order between the


conflicting transactions when they will execute. Timestamp-based
protocols manage conflicts as soon as an operation is created.

Example:

Suppose there are there transactions T1, T2, and T3.


T1 has entered the system at time 0010
T2 has entered the system at 0020
T3 has entered the system at 0030
Priority will be given to transaction T1, then transaction T2 and lastly
Transaction T3.

Timestamp Ordering Protocol –


The main idea for this protocol is to order the transactions based on their
Timestamps. A schedule in which the transactions participate is then
serializable and the only equivalent serial schedule permitted has the
transactions in the order of their Timestamp Values. Stating simply, the
schedule is equivalent to the particular Serial Order corresponding to
the order of the Transaction timestamps. An algorithm must ensure that,
for each item accessed by Conflicting Operations in the schedule, the
order in which the item is accessed does not violate the ordering. To
ensure this, use two Timestamp Values relating to each database item X.
 W_TS(X) is the largest timestamp of any transaction that
executed write(X) successfully.
 R_TS(X) is the largest timestamp of any transaction that
executed read(X) successfully.

CONCLUSION-
concurrency schedule is parallel execution of multiple transaction.while
executing transaction concurrently if execution does not execute in
current sequence,that they may lead to inconsistency in database.thus to
maintain consistence to database,different protocol are required to
use.locking which we have implemented is part of concurrency handling
Experiment No. 11

Aim: Write a Program to perform database connectivity (JDBC-ODBC).


Theory:
JDBC stands for Java Database Connectivity, which is a standard Java
API for database independent connectivity between the Java
programming language and a wide range of databases. Fundamentally,
JDBC is a specification that provides a complete set of interfaces that
allows for portable access to an underlying database. JDBC provides the
same capabilities as ODBC, allowing Java programs to contain database-
independent code. JDBC -Database Connection:The programming
involved to establish a JDBC connection follows four simple steps:
• Import JDBC Packages: Add import statements to your Java program
to import required classes in your Java code. The Import statements tell
the Java compiler where to find the classes you reference in your code
and are placed at the very beginning of your source code.
• Register JDBC Driver: This step causes the JVM to load the desired
driver implementation into memory so it can fulfill your JDBC requests.
The most common approach to register a driver is to use Java's
Class.forName() method, to dynamically load the driver's class file into
memory, which automatically registers it. This method is preferable
because it allows you to make the driver registration configurable and
portable.
• Database URL Formulation: This is to create a properly formatted
address that points to the database to which you wish to connect. After
loading the driver, you can establish a connection using the
DriverManager.getConnection() method. For easy reference, the three
overloaded DriverManager.getConnection() methods are−
• getConnection(String url)
• getConnection(String url, Properties prop)
• getConnection(String url, String user, String password)
Here each form requires a database URL. A database URL is an address
that points to your database. Formulating a database URL is where most
of the problems associated with establishing a connection occurs.
For Oracle:
ORACLE
oracle.jdbc.driver.OracleDriver jdbc:oracle:thin:@hostname:port
Number:databaseName
Create Connection Object: Finally, code a call to the
DriverManagerobject's getConnection( ) method to establish actual
database connection.
JDBC Statements:
The JDBC Statement and PreparedStatement interfaces define the
methods and properties that enable you to send SQL or PL/SQL
commands and receive data from your database.
Creating Statement ObjectBefore you can use a Statement object to
execute a SQL statement, you need to create one using the Connection
object's createStatement( ) method
.
The PreparedStatement Objects
The PreparedStatement interface extends the Statement interface, which
gives you added functionality with a couple of advantages over a generic
Statement object. Use it when you plan to use the SQL statements many
times. The PreparedStatement interface accepts input parameters at
runtime.
Result Statement:
The SQL statements that read data from a database query, return the data
in a result set. The SELECT statement is the standard way to select rows
from a database and view them in a result set. The java.sql.ResultSet
interface represents the result set of a database query. A ResultSet object
maintains a cursor that points to the current row in the result set. The term
"result set" refers to the row and column data contained in a ResultSet
object. The methods of the ResultSet interface can be broken down into
three categories −
• Navigational methods: Used to move the cursor around.
• Get methods: Used to view the data in the columns of the current row
being pointed by the cursor.
• Update methods: Used to update the data in the columns of the current
row. The updates can then be updated in the underlying database as well.
Algorithm:
1. Create table in database.
2. Later, register the driver as, Class.forName(Driver_name);
3. Now establish connection by, getConnection(String url, String user,
String password)
4. Now, create statement to execute SQL query; createStatement( )
5. Now insert data into already created table using result statement.
6. Display the table using result set

.Conclusion:
Thus, we have written a java program to make JDBC connection and
retrieve the data from the respective table.

You might also like