You are on page 1of 60

SYED AMMAL ENGINEERING COLLEGE

(An ISO 9001: 2015 Certified Institution)


(NBA Accredited Courses: CSE, MECH)
Dr. E.M.Abdullah Campus, Ramanathapuram – 623 502
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CS8481 – Database Management Systems


Laboratory

Student Lab Manual

Submitted By
Mr. G. Saravanakumar
Assistant Professor
Department of Computer Science and Engineering
VISION AND MISSION
COMPUTER SCIENCE AND ENGINEERING DEPARTMENT
VISION
Emerge as Centre of excellence in Computer Science and Engineering through quality education,
research and innovation.
MISSION
 To provide quality engineering education to the students through state-of-art facilities in
Computer Science and Engineering.
 To enrich students knowledge towards research, entrepreneur skill and employability.
 To inculcate value-based, socially committed professionalism to the cause of overall
development of students and society.

PROGRAMME EDUCATIONAL OBJECTIVES(PEOs)


Graduates of Computer Science and Engineering shall:
PEO1 Have fundamental and advanced knowledge in Computer Science along inter-disciplinary
knowledge so as to comprehend, analyze, design and create innovative solutions for real
life problems.
PEO2 Excel in professional career, higher education and research.
PEO3 Demonstrate professionalism, entrepreneurship, ethical behavior, communication skills
and collaborative team work to adapt the emerging trends by engaging in lifelong
learning.

PROGRAMME SPECIFIC OUTCOMES


PROGRAMME SPECIFIC OUTCOMES (PSOs):
At the end of the course the students will be able to
PSO1 Apply the concepts of data structure, operating systems, algorithms, database
management systems, computing and technology to formulate the real time problems.
PSO2 Design and develop innovative software with varying complexity using modern computer
languages, environments and platforms to attain entrepreneurship and employability.
INDEX
LST OF EXPERIMENTS
S. No Name of the Experiment CO PO PSO
Data Definition Commands, Data Manipulation
Commands for inserting, deleting, updating and
1 CO1 1,3,10,12 1, 2
retrieving Tables and Transaction Control
statements
Database Querying – Simple queries, Nested
2 CO2 1,3,10,12 1, 2
queries, Sub queries and Joins
3 Views, Sequences, Synonyms CO3 1,3,10,12 1, 2
4 PL/SQL (Additional Experiment) CO3 1,3,10,12 1, 2
Database Programming: Implicit and Explicit
5 CO3 1,3,10,12 1, 2
Cursors
6 Procedures and Functions CO3 1,3,10,12 1, 2
7 Triggers CO4 1,3,10,12 1, 2
8 Exception Handling CO4 1,3,10,12 1, 2
Database Design using ER modeling,
CO1,CO2
9 normalization and Implementation for any 1,3,10,12 1, 2
application
10 Database Connectivity with Front End Tools CO5 1,2,3,5,9,10,11,12 1, 2
11 Case Study using real life database applications CO5 1,2,3,5,9,10,11,12 1, 2

Prepared By Approved by

G. Saravanakumar Dr. B. Muthu Kumar


Assistant Prof., Dept. of CSE Prof. & Head, Dept. of CSE
CS8481 DATABASE MANAGEMENT SYSTEMS LABORATORY LTPC
0042

AIM: The aim of this laboratory is to inculcate the abilities of applying the principles of the
database management systems. This course aims to prepare the students for projects where a
proper implementation of databases will be required.

OBJECTIVES:
 To understand data definitions and data manipulation commands
 To learn the use of nested and join queries
 To understand functions, procedures and procedural extensions of data bases
 To be familiar with the use of a front end tool
 To understand design and implementation of typical database applications

EXPERIMENTS:
1. Data Definition Commands, Data Manipulation Commands for inserting, deleting, updating
and retrieving Tables and Transaction Control statements
2. Database Querying – Simple queries, Nested queries, Sub queries and Joins
3. Views, Sequences, Synonyms
4. Database Programming: Implicit and Explicit Cursors
5. Procedures and Functions
6. Triggers
7. Exception Handling
8. Database Design using ER modeling, normalization and Implementation for any application
9. Database Connectivity with Front End Tools
10. Case Study using real life database applications
TOTAL: 60 PERIODS
OUTCOMES:
Upon completion of the course, the students will be able to:
 Use typical data definitions and manipulation commands.
 Design applications to test Nested and Join Queries
 Implement simple applications that use Views
 Implement applications that require a Front-end Tool
 Critically analyze the use of Tables, Views, Functions and Procedures
Experiment No 1:
Data Definition Commands, Data Manipulation Commands for inserting, deleting,
updating and retrieving Tables and Transaction Control statements
Aim:
To execute Data Definition Commands, Data Manipulation Commands for
inserting,deleting, updating and retrieving Tables and Transaction Control statements.

Data Definition Language:


DDL(Data Definition Language) statements are used to create, delete, or change the
objects of a database. Typically a database administrator is responsible for using DDL statements
or production databases in a large database system. The commands used are:

● Create - It is used to create a table.


● Alter - This command is used to add a new column, modify the existing column definition and
to include or drop integrity constraint.
● Drop - It will delete the table structure provided the table should be empty.
● Desc - This is used to view the structure of the table.

Creation:
Create command is used to create a new table.
Syntax
create table <table name>
{
fieldname-1 datatype constraints if any,
fieldname-2 datatype constraints if any,
…….
fieldname-n datatype constraints if any,
};

Syntax for creating table from another table:


create table <table name> as
(
select(att-list) from <existing table name>
);

DESCRIBING TABLE
Desc <tablename>;

REFERENCING ANOTHER USER TABLE


Table belonging to other users are not in the user’s schema, we should use the owner’s
name as prefix to those tables.

Select * from user name .table name

Constraints:
The three types of constraints are Domain Integrity Constraints, Entity Integrity Constraints, and
Referential Integrity Constraints. Integrity Constraints are used to enforce rules that the columns
in a table have to conform with. It is a mechanism used by Oracle to prevent invalid data entry
into the table.
1. Domain Integrity Constraints
a. Not Null Constraint – The enforcement of Not Null Constraints in a table ensures that
the table contains values.
b. Check Constraint – Allow only a particular range of values

2. Entity Integrity Constraints


a. Unique Constraints – The unique constraint designates a Column or a group of
columns as unique key. This allows only unique value to be stored in the column. Rejects
duplication.
b. Primary Key Constraints – Primary key similar to unique key. avoids duplication ,
relation between two tables , does not allow not null values.
3. Referential Integrity Constraints
Enforces relationship between tables. It designates a column or group of columns as a
foreign key.

DROP TABLE
1. All data and structure in the table is deleted
2. Any pending transactions are committed.
3. All indexes are dropped.
4. We can not rollback the drop table statement.

Syntax: drop table <table name>;

Exercise:

1. Create a table for student database, which has the following attributes attributes such as,
register number of the students, name of the students, date of birth, department, year of
study, address.
2. Display the structure of the table.
3. Add a new field phone number to the table.
4. Modify the size of address field in the table.
5. Drop the table.

Data Manipulation Language


DML commands are the most frequently used SQL commands and is used to query and
manipulate the existing database objects. Some of the commands are
1. Insert
2. Select
3. Update
4. Delete
5. Truncate
INSERT:
This is used to add one or more rows to a table. The values are separated by commas and
the data types char and date are enclosed in apostrophes. The values must br entered in the same
order as they are defined.
Inserting a single row into a table:
insert into <table name> values(fieldvalue-1,fieldvalue-2,…,fieldvalue-n);

Inserting more than one record using a single insert command:


insert into <table name> values(&fieldname-1,&fieldname-2,…&fieldname-n);

UPDATE - It is used to alter the column values in a table. A single column may be updated or
more than one column could be updated.
Syntax:
update <table name> set(fieldname-1 = value, fieldname-2 = value,…,fieldname-n = value)
[WHERE <condition/expression>];

DELETE - After inserting row in a table we can also delete them if required. The delete
command consists of a from clause followed by an optional where clause.

Syntax:
delete from <table name> [where <condition/expression>];

TRUNCATE - If there is no further use of records stored in a table and the structure has to be
retained, then the records alone can be deleted.
Syntax:
Truncate table <table name>

Transaction Control Language:


Transaction Control Language(TCL) commands are used to manage transactions in the
database. These are used to manage the changes made to the data in a table by DML statements.
It also allows statements to be grouped together into logical transactions.

Commit: This command is used to save the changes made by the DML statements.
Roll Back: This command restores the database to last commited state. It is also used
with SAVEPOINT command to jump to a savepoint in an ongoing transaction.
SAVEPOINT: This command is used to temporarily save a transaction so that you can rollback
to that point whenever required.

Exercise:
1. Create a table that contains information about Students with fields Regno, Name, DOB, Age,
Sex, Department, Subject 1, Subject 2, Subject 3, Total. The Regno is a unique field and the
sex should contain the value either ‘M’ or ‘F’.
2. Insert records in the table.
3. Add a new field average to the student table.
4. Update the total and Average of the Students.
5. Display the student details
6. Display the student details whose average is greater than 70
7. Display the details of the students whose average is between 70 and 80.
8. Find the students whose name starts with the letter ‘A’.
9. Display the student name without duplication.
10. Delete the students whose name starts with the letter ‘C’.
11. Create 3 save points
12. Rollback to the savepoints.

Result:

Thus the DDL, DML and TCL command were executed and the outputs are verified.
Experiment No: 02

Database Querying – Simple queries, Nested queries, Sub queries and Joins

AIM:

To write queries using Set operations, to write nested queries and also to write queries using
clauses such as GROUP BY, ORDER BY, etc. and retrieving information by joining tables.

SET OPERATIONS & OTHER CLAUSES:

NESTED QUERY: - A nested query makes use of another sub-query to compute or retrieve the
information.

UNION - OR

INTERSECT - AND

EXCEPT - NOT

Order by : The order by clause is used to display the results in sorted order.

Group by : The attribute or attributes given in the clauses are used to form groups. Tuples with
the same value on all attributes in the group by clause are placed in one group.

Having: SQL applies predicates (conditions) in the having clause after groups have been formed,
so aggregate function be used.

Queries:
1. Create a the following tables
a. Employee ( Employee_number, EName, Street, City)
b. Works(Ename, Cname, salary)
c. Manager(Cname, MName)
2. Find all the employees who live in the same city as the company for which they work.
3. Find the second maximum salary of the employee.
4. Find the employees who earn more than the average salary of all employees of their
company.
5. Find the company that has the smallest payroll.
6. Find the company that has more number of employees.
7. Apply joins between employee and Manager.
Employee:

EMP_NAME STREET CITY


Ragav North St Ramnad
Anand SS Kovil st Paramakudi
Mani South St Tirunelveli
Siva West St Chennai

Works

EMP_NAME COMPANY_NAME SALARY


Ragav SAEC 50000
Anand SAEC 35000
Mani Infosys 38000
Siva TCS 36000

Company
COMPANY_NAME CITY
SAEC Ramnad
TCS Chennai
Infosys Chennai

Manager:

EMP_NAME MANAGER_NAME
Ragav Charli
Anand Charli
Mani Murali
Siva Sampath

1. Find all the employees who live in the same city as the company for which they work.

select employee.emp_name,works.company_name from employee, works,company where


employee.emp_name=works.emp_name and works.company_name = company.company_name
and employee.city=company.city

EMP_NAME COMPANY_NAME
Ragav SAEC
Siva TCS
2. Find the second maximum salary of the employee.

select max(salary) from works where salary<(select max(salary) from works)

MAX(SALARY)
38000

3. Find the employees who earn more than the average salary of all employees of their
company.
select emp_name,salary from works where salary > (select avg(salary) from works)

EMP_NAME SALARY
Ragav 50000

4. Find the company that has the smallest payroll.

select company_name,salary from works where salary =(select min(salary) from works)

COMPANY_NAME SALARY
SAEC 35000

5. Find the company that has more number of employees.


select company_name, count(emp_name) from works group by company_name

COMPANY_NAME COUNT(EMP_NAME)
Infosys 1
SAEC 2
TCS 1

6. Apply joins between employee and Manager.

select * from employee natural join manager

EMP_NAME STREET CITY MANAGER_NAME


Ragav North St Ramnad Charli
Anand SS Kovil st Paramakudi Charli
Mani South St Tirunelveli Murali
Siva West St Chennai Sampath

Result:

The the queries for nested, sub queries and join are executed and their outputs are
verified.
Experiment No: 03

Views, Sequences, Synonyms


Aim:
To create and execute the Views, Synonyms, Sequence in SQL.

View:
In SQL a view is a virtual table based on the result-set of an SQL statement. A view
contains rows and columns, just like a real table. The fields in a view are fields from one or more
real tables in the database. You can add SQL functions, WHERE, and JOIN statements to a view
and present the data as if the data were coming from one single table.
Syntax:
CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition;
Example:
CREATE VIEW Outstanding as
Select * from students
where grade = ‘S’;

Retrieving from a View:


SQL:/>Select name from outstanding;

SQL Updating a View:


CREATE OR REPLACE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
Drop a view:
Syntax:
Drop VIEW view_name;

Synonym:
A synonym is an alternative name for objects such as tables, views, sequences, stored
procedures, and other database objects.

Syntax:
CREATE [OR REPLACE] [PUBLIC] SYNONYM [schema .] synonym_name
FOR [schema .] object_name [@ dblink];
Where
 OR REPLACE allows you to recreate the synonym (if it already exists) without having to
issue a DROP synonym command.
 PUBLIC means that the synonym is a public synonym and is accessible to all users.
Remember though that the user must first have the appropriate privileges to the object to
use the synonym.
 schema is the appropriate schema. If this phrase is omitted, Oracle assumes that you are
referring to your own schema.
 object_name is the name of the object for which you are creating the synonym. It can be
one of the following:
 table
 view
 sequence
 stored procedure
 function
 package
 materialized view
 java class schema object
 user-defined object
 synonym
Example:
CREATE PUBLIC SYNONYM suppliers FOR app.suppliers;
Retrieving from Synonym:
SELECT * FROM suppliers;
Drop synonym
DROP [PUBLIC] SYNONYM [schema .] synonym_name [force];
Where
 PUBLIC allows you to drop a public synonym.
 force will force Oracle to drop the synonym even if it has dependencies. It is probably
not a good idea to use force as it can cause invalidation of Oracle objects

Example:
DROP PUBLIC SYNONYM suppliers;
Sequence:
In Oracle, you can create an auto number field by using sequences. A sequence is an
object in Oracle that is used to generate a number sequence. This can be useful when you need to
create a unique number to act as a primary key.
Syntax
CREATE SEQUENCE sequence_name
MINVALUE value
MAXVALUE value
START WITH value
INCREMENT BY value
CACHE value;
Example:
CREATE SEQUENCE supplier_seq
MINVALUE 1
START WITH 1
INCREMENT BY 1
CACHE 20;
INSERT INTO suppliers (supplier_id, supplier_name) VALUES (supplier_seq.NEXTVAL,
'Kraft Foods');
*Supplier_seq.NEXTVAL provides the next value in the sequence to the supplier_id field.

Drop Sequence:
Syntax:
DROP SEQUENCE sequence_name;

Queries:
1. Create a view Manager from Employee table with field Employee Id, Name and
Designation.
SQL/> create view manager as
Select * from employee;
Output:
View created
2. Display all information from the view.
SQL/> Select * from Manager;

3. Drop the view.


SQL/>Drop view manager;

4. Create a synonym for employee table, Make it as public and available to all.
SQL/>create public synonym maxi for employee;
Output:
Synonym created

5. Write a query to retrieve from synonym.


SQL/>Drop public synonym maxi

6. Write a query to drop the synonym.


7. SQL/>Drop public synonym maxi

8. Create a sequence id_seq in employee table.


SQL/>Create sequence placement
Minvalue 1
Maxvalue 25
Start with 1
Increment by 1
Cache 20;

Output:
Sequence created.

9. Insert a record in employee table using a sequence.


SQL/>Insert into employee values(placement.nextval, ‘&name’,’&designation’);

10. Check whether the insertion is correct or not.


SQL/>select * from employee;

Result:

Thus the view, synonyms, sequence, index are created and executed successfully and its outputs
are verified.
Experiment No: 04

PL/SQL

Aim:

To write and execute PL/SQL programs

Basic Syntax of PL/SQL


DECLARE
/* Variables can be declared here */
BEGIN
/* Executable statements can be written here */
EXCEPTION
/* Error handlers can be written here. */
END;
Statements in PL/SQL block:
Decision making statement (IF Statement):
Syntax:
IF(TEST_CONDITION) THEN
SET OF STATEMENTS
ELSE
SET OF STATEMENTS
END IF;

IF - ELSIF - ELSE Statement:


IF(TEST_CONDITION) THEN
SET OF STATEMENTS
ELSIF (CONDITION)
SET OF STATEMENTS
END IF;

LOOPING STATEMENTS:-
The SQL supports number of looping statements like GOTO, FOR, WHILE & LOOP.
GOTO STATEMENTS
<<LABEL>>
SET OF STATEMENTS
GOTO LABEL;

FOR LOOP
FOR <VAR> IN [REVERSE] <INI_VALUE>..<END_VALUE>
SET OF STATEMENTS
END LOOP;

WHILE LOOP
WHILE (CONDITION) LOOP
SET OF STATEMENTS
END LOOP;

LOOP STATEMENT
LOOP
SET OF STATEMENTS
IF (CONDITION) THEN
EXIT
SET OF STATEMENTS
END LOOP;

While using LOOP statement, we have take care of EXIT condition, otherwise it may go into
infinite loop.

Programs:
1. Write a PL/SQL Program to find the biggest of three numbers.
2. Write a PL/SQL Program to generate number series.
3. Write a PL/SQL Program to display the number series using while loop statements.
4. Write a PL/SQL Program to generate Fibonacci series.
5. Write a PL/SQL Program to check then given number is Armstrong number or not.
6. Write a PL/SQL Program to find the reverse of the given number.
7. Write a PL/SQL program to generate number series.

Programs:
TO DISPLAY HELLO MESSAGE

SQL> set serveroutput on;


SQL> declare
a varchar2(20);
begin
a:='Hello';
dbms_output.put_line(a);
end;
/
Output:
Hello
PL/SQL procedure successfully completed.

GREATEST OF THREE NUMBERS


SQL> set serveroutput on;
SQL> declare
2 a number(7);
3 b number(7);
4 c number(7);
5 begin
6 a:=&a;
7 b:=&b;
8 c:=&c;
9 if(a>b and a>c) then
10 dbms_output.put_line (' The greatest of the three is ' || a);
11 else if (b>c) then
12 dbms_output.put_line (' The greatest of the three is ' || b);
13 else
14 dbms_output.put_line (' The greatest of the three is ' || c);
15 end if;
16 end if;
17 end;
18 /
Output:
Enter value for a: 5
old 6: a:=&a;
new 6: a:=5;
Enter value for b: 7
old 7: b:=&b;
new 7: b:=7;
Enter value for c: 1
old 8: c:=&c;
new 8: c:=1;
The greatest of the three is 7
PL/SQL procedure successfully completed.

PRINT NUMBERS FROM 1 TO 5 USING SIMPLE LOOP


SQL> set serveroutput on;
SQL> declare
2 a number:=1;
3 begin
4 loop
5 dbms_output.put_line (a);
6 a:=a+1;
7 exit when a>=5;
8 end loop;
9 end;
10 /
Output:
1
2
3
4
5
PL/SQL procedure successfully completed.

PRINT NUMBERS FROM 1 TO 4 USING WHILE LOOP


SQL> set serveroutput on;
SQL> declare
2 a number:=1;
3 begin
4 while(a<5)
5 loop
6 dbms_output.put_line (a);
7 a:=a+1;
8 end loop;
9 end;
10 /
Output:
1

2
3
4
PL/SQL procedure successfully completed.

PRINT NUMBERS FROM 1 TO 5 USING FOR LOOP


SQL> set serveroutput on;
SQL> declare
2 a number:=1;
3 begin
4 for a in 1..5
5 loop
6 dbms_output.put_line (a);
7 end loop;
8 end;
9/
Output:
1
2
3
4
5
PL/SQL procedure successfully completed.

RESULT
Thus the basic programs in PL/SQL block has been executed and verified.
Experiment No:05

PL/SQL Cursors
Aim:

To write a PL/SQL Program to manipulate the table using explicit cursor.

Procedure:

Oracle creates a memory area, known as the context area, for processing an SQL statement,
which contains all the information needed for processing the statement.

A cursor is a pointer to this context area. PL/SQL controls the context area through a cursor. A
cursor holds the rows (one or more) returned by a SQL statement. The set of rows the cursor
holds is referred to as the active set.

There are two types of cursors −

 Implicit cursors
 Explicit cursors
Implicit Cursors
Implicit cursors are automatically created by Oracle whenever an SQL statement is executed,
when there is no explicit cursor for the statement. Programmers cannot control the implicit
cursors and the information in it.

Explicit Cursors
Explicit cursors are programmer-defined cursors for gaining more control over the context
area. An explicit cursor should be defined in the declaration section of the PL/SQL Block. It is
created on a SELECT Statement which returns more than one row.

The syntax for creating an explicit cursor is −

CURSOR cursor_name IS select_statement;


Working with an explicit cursor includes the following steps −

 Declaring the cursor for initializing the memory


 Opening the cursor for allocating the memory
 Fetching the cursor for retrieving the data
 Closing the cursor to release the allocated memory
Declaring the Cursor
Declaring the cursor defines the cursor with a name and the associated SELECT statement. For
example −

CURSOR c_customers IS

SELECT id, name, address FROM customers;

Opening the Cursor


Opening the cursor allocates the memory for the cursor and makes it ready for fetching the rows
returned by the SQL statement into it. For example, we will open the above defined cursor as
follows −

OPEN c_customers;

Fetching the Cursor


Fetching the cursor involves accessing one row at a time. For example, we will fetch rows from
the above-opened cursor as follows −

FETCH c customers INTO c_id, c_name, c_addr;

Closing the Cursor


Closing the cursor means releasing the allocated memory. For example, we will close the
above-opened cursor as follows −

CLOSE c customers;

The following table provides the description of the most used attributes −

S.No Attribute & Description

1 %FOUND

Returns TRUE if an INSERT, UPDATE, or DELETE statement affected one or more


rows or a SELECT INTO statement returned one or more rows. Otherwise, it returns
FALSE.

%NOTFOUND

The logical opposite of %FOUND. It returns TRUE if an INSERT, UPDATE, or


2
DELETE statement affected no rows, or a SELECT INTO statement returned no rows.
Otherwise, it returns FALSE.

%ISOPEN
3 Always returns FALSE for implicit cursors, because Oracle closes the SQL cursor
automatically after executing its associated SQL statement.

%ROWCOUNT
4 Returns the number of rows affected by an INSERT, UPDATE, or DELETE statement,
or returned by a SELECT INTO statement.

Example
Following is a complete example to illustrate the concepts of explicit cursors;

DECLARE

c_id customers.id%type;

c_name customerS.No.ame%type;

c_addr customers.address%type;

CURSOR c_customers is

SELECT id, name, address FROM customers;

BEGIN

OPEN c_customers;

LOOP
FETCH c_customers into c_id, c_name, c_addr;

EXIT WHEN c_customers%notfound;

dbms_output.put_line(c_id || ' ' || c_name || ' ' || c_addr);

END LOOP;

CLOSE c_customers;

END;

Exercise:

1. Create a table worker with attributes worker id, name, job, dept_no, and salary. The job
must be a manager or clerk or assistant.
2. Insert appropriate values in the table.
3. Write a PL/SQL program to display the content of the table.
4. Write a PL/SQL program to insert s row in the table.
5. Write a cursor program to insert the values into the table.
6. Write a cursor program to update the salary of manager as 500, clerk as 200 and assistant
as 100 in the worker table until the records are found.
7. Write a cursor program to count the number of rows fetched.

Programs:

declare
e_no emp.eno%type;
e_name emp.ename%type;
sal emp.salary%type;
dep emp.dept%type;
cursor c1 is select eno,ename,salary,dept from emp;
begin
open c1;
loop
fetch c1 into e_no,e_name,sal,dep;
dbms_output.put_line(e_no||e_name||sal||dep);
exit when c1%notfound;
end loop;
close c1;
end;

declare
e_no emp.eno%type;
e_name emp.ename%type;
sal emp.salary%type;
dep emp.dept%type;
cursor c1 is select eno,ename,salary,dept from emp;
begin
e_no:=&e_no;
e_name:='&e_name';
sal:=&sal;
dep:='&dep';
open c1;
insert into emp values(e_no,e_name,sal,dep);
close c1;
end;&dep';
open c1;
insert into emp values(e_no,e_name,sal,dep);
end loop;
close c1;
end;

declare
cursor c1 is select eno,ename,salary,dept from emp;
e_no emp.eno%type;
e_name emp.ename%type;
sal emp.salary%type;
dep emp.dept%type;
rno number(3);
begin
open c1;
loop
fetch c1 into e_no,e_name,sal,dep;
if c1%found then
rno:=c1%rowcount;
end if;
end loop;
dbms_output.put_line('Row Count is = '||rno);
close c1;
end;

Result:

Thus the PL/SQL program for implicit and explicit cursor is performed and the outputs
are verified.
Experiment No: 06

Procedures and Functions

AIM:
To solve the given problem statements using procedures.

PL/SQL PROCEDURES:
Procedures are the subprograms that do not return a value directly. It is mainly used to
perform action.

SYNTAX:
CREATE [OR REPLACE] PROCEDURE procedure_name
[(parameter_name [IN | OUT | IN OUT] type [, ...])]
{IS | AS}
BEGIN
< procedure_body >
END procedure_name;

Where,
 procedure-name specifies the name of the procedure.
 [OR REPLACE] option allows the modification of an existing procedure.
 The optional parameter list contains name, mode and types of the
parameters. IN represents the value that will be passed from outside and OUT represents
the parameter that will be used to return a value outside of the procedure.
 procedure-body contains the executable part.
 The AS keyword is used instead of the IS keyword for creating a standalone procedure.

Executing a Standalone Procedure


A standalone procedure can be called in two ways −
 Using the EXECUTE keyword
 Calling the name of the procedure from a PL/SQL block
Deleting a Standalone Procedure
A standalone procedure is deleted with the DROP PROCEDURE statement.
Syntax for deleting a procedure is –
DROP PROCEDURE procedure-name;

PL/SQL Functions:
A PL/SQL function is same as a procedure except that it returns a value. A standalone function is
created using the CREATE FUNCTION statement.

SYNTAX
CREATE [OR REPLACE] FUNCTION function_name (parameter_name [IN | OUT | IN OUT]
type [, ...])
RETURN return_datatype
{IS | AS}
BEGIN
<function_body>
END;

Program:
1. Write a stand alone procedure in pl/sql.

CREATE OR REPLACE PROCEDURE greetings


AS
BEGIN
dbms_output.put_line('Hello World!');
END;

2. Write a procedure to find the maximum of two numbers using IN and Out
parameter.

PROCEDURE findMin(x IN number, y IN number, z OUT number) IS


BEGIN
IF x < y THEN
z:= x;
ELSE
z:= y;
END IF;
END;

PL/SQL program that uses the procedure


DECLARE
a number;
b number;
c number;
BEGIN
a:= 23;
b:= 45;
findMin(a, b, c);
dbms_output.put_line(' Minimum of (23, 45) : ' || c);
END;

3. Write a procedure to find the square of a number usinf IN and OUT parameter.
PROCEDURE squareNum(x IN OUT number) IS
BEGIN
x := x * x;
END;

DECLARE
a number;
BEGIN
a:= 23;
squareNum(a);
dbms_output.put_line(' Square of (23): ' || a);
END;

4. Write a standalone function to find the total number of records in the table.
CREATE OR REPLACE FUNCTION totalCustomers
RETURN number IS
total number(2) := 0;
BEGIN
SELECT count(*) into total
FROM customers;

RETURN total;
END;

Calling a function:
DECLARE
c number(2);
BEGIN
c := totalCustomers();
dbms_output.put_line('Total no. of Customers: ' || c);
END;

5. Write a function in PL/SQL to find the minimum of two numbers.

DECLARE
a number;
b number;
c number;
FUNCTION findMax(x IN number, y IN number)
RETURN number
IS
z number;
BEGIN
IF x > y THEN
z:= x;
ELSE
Z:= y;
END IF;
RETURN z;
END;
BEGIN
a:= 23;
b:= 45;
c := findMax(a, b);
dbms_output.put_line(' Maximum of (23,45): ' || c);
END;
6. Write a recursive function to find the factorial of the given number.

FUNCTION fact(x number)


RETURN number
IS
f number;
BEGIN
IF x=0 THEN
f := 1;
ELSE
f := x * fact(x-1);
END IF;
RETURN f;
END;

DECLARE
num number;
factorial number;
BEGIN
num:= 6;
factorial := fact(num);
dbms_output.put_line(' Factorial '|| num || ' is ' || factorial);
END;

Result:
Thus PL/SQL Procedures and functions were created and its outputs are verified.
Experiment No:7
Triggers

Aim:
To write a PL/SQL program to perform high level language extension using trigger.

Procedure:
Trigger is a statement that executes automatically as a side effect of modification of the
database. Triggers are, in fact, written to be executed in response to any of the following events −

 A database manipulation (DML) statement (DELETE, INSERT, or UPDATE)

 A database definition (DDL) statement (CREATE, ALTER, or DROP).

 A database operation (SERVERERROR, LOGON, LOGOFF, STARTUP, or


SHUTDOWN).

Triggers can be defined on the table, view, schema, or database with which the event is
associated.

There are two conditions in executing the trigger:

1. When to execute the trigger.

2. What action should be performed when the condition is met

Benefits of Triggers:
Triggers can be written for the following purposes −

 Generating some derived column values automatically


 Enforcing referential integrity
 Event logging and storing information on table access
 Auditing
 Synchronous replication of tables
 Imposing security authorizations
 Preventing invalid transactions
Syntax of Trigger:
CREATE [OR REPLACE ] TRIGGER trigger_name
{BEFORE | AFTER | INSTEAD OF }
{INSERT [OR] | UPDATE [OR] | DELETE}
[OF col_name]
ON table_name
[REFERENCING OLD AS o NEW AS n]
[FOR EACH ROW]
WHEN (condition)
DECLARE
Declaration-statements
BEGIN
Executable-statements
EXCEPTION
Exception-handling-statements
END;

Where,

 CREATE [OR REPLACE] TRIGGER trigger_name − Creates or replaces an existing


trigger with the trigger_name.

 {BEFORE | AFTER | INSTEAD OF} − This specifies when the trigger will be executed.
The INSTEAD OF clause is used for creating trigger on a view.

 {INSERT [OR] | UPDATE [OR] | DELETE} − This specifies the DML operation.

 [OF col_name] − This specifies the column name that will be updated.

 [ON table_name] − This specifies the name of the table associated with the trigger.

 [REFERENCING OLD AS o NEW AS n] − This allows you to refer new and old values
for various DML statements, such as INSERT, UPDATE, and DELETE.
 [FOR EACH ROW] − This specifies a row-level trigger, i.e., the trigger will be executed
for each row being affected. Otherwise the trigger will execute just once when the SQL
statement is executed, which is called a table level trigger.

 WHEN (condition) − This provides a condition for rows for which the trigger would fire.
This clause is valid only for row-level triggers.

Exercise 01:
The details about the students mark are being in the stu table with attributes. Name, Rollno,
mark, Mark2, Mark3.
The stu1 table consists of attributes, Rollno, Total, Average, Result.
The details of the first table are being given in the prompt by the user. The total, average are
processed for currently processed row in the stu table using after insert on trigger the values are
placed in the table stu1.

Trigger:
CREATE or REPLACE TRIGGER student
AFTER INSERT ON stu
REFERENCING OLD AS o NEW AS n
FOR EACH ROW
declare
total number(3);
avge number(5,2);
result varchar2(10);
begin
total:=:n.mark1+:n.mark2+:n.mark4;
avge:=total/3;
if (:n.mark1>=50 and :n.mark2>=50 and :n.mark3>=50) then
result:='pass'
else
result:='fail'
end if;
insert into stu1 values(:n.rollno,total,avge,result);
end;
Trigger created
SQL>insert into st1 values(‘raja’,004,100,99,90)
1 row created

SQL>select * from st2;

ROLLNO TOTAL AVG RESULT


4 289 96 Pass

Exercise 2:
Create a table customer with the following fields Id, Name, Age, Address, and Salary.
Write a trigger to display the difference in salary when the following operations such as Insert,
Delete or Update take place in the above table.
Trigger:

CREATE OR REPLACE TRIGGER display_salary_changes


BEFORE DELETE OR INSERT OR UPDATE ON customers
FOR EACH ROW
WHEN (NEW.ID > 0)
DECLARE
sal_diff number;
BEGIN
sal_diff := :NEW.salary - :OLD.salary;
dbms_output.put_line('Old salary: ' || :OLD.salary);
dbms_output.put_line('New salary: ' || :NEW.salary);
dbms_output.put_line('Salary difference: ' || sal_diff);
END;
RESULT:
Thus the high - level language extension with triggers has been performed for generating the
students mark list.
Experiment No:08
Exception Handling
Aim:
To write a PL/SQL program to handle Exceptions.

PL/SQL Exception:

An error condition during a program execution is called an exception in PL/SQL. PL/SQL


supports programmers to catch such conditions using EXCEPTION block in the program and
an appropriate action is taken against the error condition. There are two types of exceptions:

 System-defined exceptions

 User-defined exceptions

SYNTAX

DECLARE
<declarations section>
BEGIN
<executable command(s)>
EXCEPTION
<exception handling goes here >
WHEN exception1 THEN
exception1-handling-statements
WHEN exception2 THEN
exception2-handling-statements
WHEN exception3 THEN
exception3-handling-statements
........
WHEN others THEN
exception3-handling-statements
END;
Raising Exceptions:

Exceptions are raised by the database server automatically whenever there is any internal
database error, but exceptions can be raised explicitly by the programmer by using the
command RAISE.

Syntax of raising an exception:

DECLARE
exception_name EXCEPTION;
BEGIN
IF condition THEN
RAISE exception_name;
END IF;
EXCEPTION
WHEN exception_name THEN
statement;
END;

User-defined Exceptions

PL/SQL allows you to define your own exceptions according to the need of your program. A
user-defined exception must be declared and then raised explicitly, using either a RAISE
statement or the procedure DBMS_STANDARD.RAISE_APPLICATION_ERROR.

Syntax:
DECLARE
my-exception EXCEPTION;
PROBLEM STATEMENT:
1. Create a table customer with fields customer id, customer name and customer address.

Program:
DECLARE
c_id cust.id%type;
c_name cust.name%type;
BEGIN
c_id:=&c_id;
SELECT id,name INTO c_id,c_name FROM cust
WHERE id=c_id;
DBMS_OUTPUT.PUT_LINE('ID = '||c_id);
DBMS_OUTPUT.PUT_LINE('Name = '||c_name);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Enter the correct id number');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Invalid data');
END;

2. Write a PL/SQL Program that invokes exception when record is not found in the table.

DECLARE
c_id cust.id%type;
c_name cust.name%type;
invalid_exception EXCEPTION;
BEGIN
c_id:=&c_id;
IF c_id<=0 THEN
RAISE invalid_exception;
ELSE
SELECT id,name INTO c_id,c_name FROM cust
WHERE id=c_id;
DBMS_OUTPUT.PUT_LINE('ID = '||c_id);
DBMS_OUTPUT.PUT_LINE('Name = '||c_name);
END IF;
EXCEPTION
WHEN INVALID_EXCEPTION THEN
DBMS_OUTPUT.PUT_LINE('Enter the Id number greater than Zero');
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Enter the correct id number');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Invalid data');
END;

Result:
Thus the PL/SQL program for exception handling is performed and the outputs are verified.
Experiment No:09
Database Design using ER modeling, normalization and Implementation for any
application

Aim:
To design a database using ER modeling, normalization and Implementation for any
application.

Entity Relationship Model:


An entity – relationship model (E-R) based on the perception of world thing that consist
of collection of object called entity and relationship among those objects.. An entity is a thing or
object in the real world that is distinguished from other objects. Each entity are described in the
database by a set of attributes.

Entity Set:

An entity set is a set of entities of the same type that share the same properties.

Example: set of all persons, companies, trees, holidays

Attributes:

An entity is represented by a set of attributes, that is descriptive properties possessed by all


members of an entity set.

Domain – the set of permitted values for each attribute

Attribute types:

 Simple and composite attributes.


 Single-valued and multi-valued attributes
E.g. multivalued attribute: phone-numbers
 Derived attributes
Can be computed from other attributes
 E.g. age, given date of birth

Relationship Set:

 A relationship is an association among several entities


 A relationship set is a mathematical relation among n  2 entities, each taken from entity
sets

{(e1, e2, … en) | e1  E1, e2  E2, …, en  En}

where (e1, e2, …, en) is a relationship

ER Diagram:

Rectangles represent entity sets.

Diamonds represent relationship sets.

Lines link attributes to entity sets and entity sets to relationship sets.

Ellipses represent attributes

Double ellipses represent multivalued attributes.

Dashed ellipses denote derived attributes.

 Underline indicates primary key attributes (will study later)

Draw a ER diagram for Hospital management identify the relationship between the entity set and
also convert the ER diagram into table.

Entity Sets:(Primary Keys are underlined)

1.Patient(Pid,p,PName, PDiagnosis,PAddress)

2.Hospital(Hosp-id,Hos-name,Haddress,Hcity)

3. Doctor(Did,Dname,Qualification,salary)

4.MediacalRecord(record-id,Date-of-examination,problem)

Result:
Thus the database was designed using ER model, normalized and converted into table
successfully.
Experiment No : 10

Database Connectivity using Front End Tool

Aim:

To write an application program to connect database with java using JDBC.

Java with MySql Connection Steps

1. Open NetBeans IDE

2. File->New Project

3. In New Project Window, Choose Java->java Application->Next

4. Give Project Name and Project Location->Finish. The new project Environment is created

5. In Project right click the source package and select New JFrame Form

6. Now Jframe Form is added in the project

7. Design the form as per the project requirements using Swing controls like Label, TextFiled,

Button, List, table etc..

8. In Project right click the Libraries and add the JAR file “mysql-connector-java-5.1.47.jar” in your

Project

9. In Source of Jframe Form add the Java MySql Connectivity Code

Design Window
Code

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

/*

* NewJFrame.java

*
* Created on Mar 8, 2019, 2:46:43 PM

*/

/**

* @author root

*/

import java.sql.*;

import javax.swing.DefaultListModel;

import javax.swing.JList;

public class NewJFrame extends javax.swing.JFrame {

static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";

static final String DB_URL = "jdbc:mysql://localhost:3306/student";

static final String USER = "root";

static final String PASS = "saecsql";

/** Creates new form NewJFrame */

public NewJFrame() {

initComponents();

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/
@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

jScrollPane1 = new javax.swing.JScrollPane();

jTable1 = new javax.swing.JTable();

jScrollPane2 = new javax.swing.JScrollPane();

jTable2 = new javax.swing.JTable();

jLabel1 = new javax.swing.JLabel();

jLabel2 = new javax.swing.JLabel();

jTextField1 = new javax.swing.JTextField();

jTextField2 = new javax.swing.JTextField();

jButton1 = new javax.swing.JButton();

jButton2 = new javax.swing.JButton();

jScrollPane3 = new javax.swing.JScrollPane();

jList1 = new javax.swing.JList();

jTable1.setModel(new javax.swing.table.DefaultTableModel(

new Object [][] {

{null, null, null, null},

{null, null, null, null},

{null, null, null, null},

{null, null, null, null}

},

new String [] {

"Title 1", "Title 2", "Title 3", "Title 4"


}

));

jScrollPane1.setViewportView(jTable1);

jTable2.setModel(new javax.swing.table.DefaultTableModel(

new Object [][] {

{null, null, null, null},

{null, null, null, null},

{null, null, null, null},

{null, null, null, null}

},

new String [] {

"Title 1", "Title 2", "Title 3", "Title 4"

));

jScrollPane2.setViewportView(jTable2);

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("Roll No");

jLabel2.setText("Name");

jButton1.setText("Save");

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {


jButton1ActionPerformed(evt);

});

jButton2.setText("Show");

jButton2.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton2ActionPerformed(evt);

});

jList1.setModel(new javax.swing.AbstractListModel() {

String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };

public int getSize() { return strings.length; }

public Object getElementAt(int i) { return strings[i]; }

});

jScrollPane3.setViewportView(jList1);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(83, 83, 83)


.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

.addComponent(jLabel2)

.addComponent(jLabel1)))

.addGroup(layout.createSequentialGroup()

.addGap(28, 28, 28)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jButton2)

.addComponent(jButton1))))

.addGap(48, 48, 48)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 112,


Short.MAX_VALUE)

.addGap(108, 108, 108))

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)

.addComponent(jTextField2)

.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 129,


Short.MAX_VALUE))

.addContainerGap(91, Short.MAX_VALUE))))

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(66, 66, 66)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(26, 26, 26)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel2)

.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(28, 28, 28)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addComponent(jButton1)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35,
Short.MAX_VALUE)

.addComponent(jButton2)

.addGap(126, 126, 126))

.addGroup(layout.createSequentialGroup()

.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap())))

);

pack();

}// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

Connection conn = null;


try{

Class.forName("com.mysql.jdbc.Driver");

System.out.println("Connecting to a selected database...");

conn = DriverManager.getConnection(DB_URL, USER, PASS);

System.out.println("Connected database successfully...");

System.out.println("Inserting records into the table...");

String sql = "INSERT INTO studentinfo (registerno, studname)" +

"VALUES (?, ?)";

PreparedStatement preparedStatement = conn.prepareStatement(sql);

preparedStatement.setInt(1, Integer.parseInt(jTextField1.getText()));

preparedStatement.setString(2, jTextField2.getText());

//preparedStatement.setString(3, "Test3");

preparedStatement.executeUpdate();

preparedStatement.close();

conn.close();

}catch(SQLException se){

//Handle errors for JDBC

System.out.println(se);

}catch(Exception e){

//Handle errors for Class.forName

System.out.println(e);

}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

Connection conn = null;

try{

Class.forName("com.mysql.jdbc.Driver");

System.out.println("Connecting to a selected database...");

conn = DriverManager.getConnection(DB_URL, USER, PASS);

System.out.println("Connected database successfully...");

System.out.println("Inserting records into the table...");

String sql = "select studname from studentinfo";

DefaultListModel model = new DefaultListModel(); //create a new list model

Statement statement = conn.createStatement();

ResultSet resultSet = statement.executeQuery(sql); //run your query

while (resultSet.next()) //go through each row that your query returns

String ItemList2 = resultSet.getString("studname"); //get the element in column "item_code"

model.addElement(ItemList2); //add each item to the model

jList1.setModel(model);

resultSet.close();

statement.close();

conn.close();

}catch(SQLException se){

//Handle errors for JDBC


System.out.println(se);

}catch(Exception e){

//Handle errors for Class.forName

System.out.println(e);

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

/* Set the Nimbus look and feel */

//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">

/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html

*/

try {

for (javax.swing.UIManager.LookAndFeelInfo info :


javax.swing.UIManager.getInstalledLookAndFeels()) {

if ("Nimbus".equals(info.getName())) {

javax.swing.UIManager.setLookAndFeel(info.getClassName());

break;

} catch (ClassNotFoundException ex) {


java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

//</editor-fold>

/* Create and display the form */

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new NewJFrame().setVisible(true);

});

// Variables declaration - do not modify

private javax.swing.JButton jButton1;

private javax.swing.JButton jButton2;

private javax.swing.JLabel jLabel1;


private javax.swing.JLabel jLabel2;

private javax.swing.JList jList1;

private javax.swing.JScrollPane jScrollPane1;

private javax.swing.JScrollPane jScrollPane2;

private javax.swing.JScrollPane jScrollPane3;

private javax.swing.JTable jTable1;

private javax.swing.JTable jTable2;

private javax.swing.JTextField jTextField1;

private javax.swing.JTextField jTextField2;

// End of variables declaration

Procedure to test the MySql DB Connection

1. In Project Services, Expand the DataBases and right click in Drives to add MtSql Driver

2. Select New Driver and click “ADD” button to add the “mysql-connector-java-5.1.47.jar” from

the saved location

3. Right click the added driver in the drivers list and click connect using menu

4. New Connection wizard is now open.

5. Put values to drivers, host, port, database, user and Password. The sample connection wizard shown
below

6. The click Test Connection Button, once succeeded that will shown below as.

7. Then click Finish Button. The new database driver is now added in the Data Base List
Result:

Thus the front end tool Java is connected with MySql using JDBC.

You might also like