Ad3381 DBDM Lab Programs Print Final
Ad3381 DBDM Lab Programs Print Final
LIST OF EXPERIMENTS:-
Exp.No Name of Experiments CO’s BL
Database Development Life cycle:
1 Problem definition and Requirement CO1 L4
analysis Scope and Constraints
Database design using Conceptual modeling (ER-EER) – top-down
2 approach Mapping conceptual to relational database and validate using CO2 L6
Normalization
Implement the database using SQL Data definition with constraints,
3 Views CO3 L6
4 Query the database using SQL Manipulation CO3 L2
Querying/Managing the database using SQL Programming
5 - Stored Procedures/Functions CO3 L2
- Constraints and security using Triggers
6 Database design using Normalization – bottom-up approach CO2 L6
Develop database applications using IDE/RAD
7 tools (Eg., NetBeans,VisualStudio)
CO4 L6
8 Database design using EER-to-ODB mapping / UML class diagrams CO5 L3
Object features of SQL-UDTs and sub-types, Tables using UDTs,
9 CO5 L2
Inheritance,Method definition
10 Querying the Object-relational database using Objet Query language CO5 L2
To study about the various concepts such as Problem definition, Requirement analysis, Scope
and Constraints involved in Database Development Life Cycle.
DESCRIPTION
DATABASE ENVIRONMENT
A database environment is a collective system of components that comprise and regulates the
group of data, management, and use of data, which consist of software, hardware, people, techniques
of handling database, and the data also. One of the primary aims of a database is to supply users with
an abstract view of data, hiding a certain element of how data is stored and manipulated.
Hardware in a database environment means the computers and computer peripherals that are
being used to manage a database,
Software includes operating system (OS) to the application programs that include database
management software like M.S. Access or SQL Server.
People in a database environment include administrators and data users in system
COMPONENTS OF DATABASE SYSTEM ENVIRONMENT
Even the database system environment is made up of the following
1. Hardware
2. Software
3. People
4. Procedures
5. Data
System Utilities: Database system utilities are the tools that can be used by the database system
administrator to control and manage the database system.
1. Loading Utility
Loading database utility helps in loading the database file into the database.
2. Backup Utility
The backup utility in the database environment helps in creating a backup copy of the entire database.
3. Database Storage Reorganization Utility
It helps to relocate and organize the database files to a different location and it also produces a new
access path to access the files from its new location.
4. Performance Monitoring Utility
It monitors the usage of the database by its user and provides statistics for the same to the DBA.
DATABASE SYSTEM DEVELOPMENT LIFECYCLE:
Database life cycle (DBLC) defines the stages involved for implementing a database,
starting with requirements analysis and ending with monitoring and modification.
DBLC never ends because database monitoring, modification, and maintenance are part of
the life cycle, and these activities continue long after a database has been implemented.
DBLC encompasses the lifetime of database.
1. Requirements analysis
2. Logical design
3. Physical design
4. Implementation
Requirements analysis
Planning – This stages of database design concepts are concerned with planning of entire Database
Development Life Cycle.
System definition – This stage defines the scope and boundaries of the proposed database system.
Requirement Analysis - Example
Below are the two methodologies used for requirement analysis phase,
1. Structured Data Analysis (SDA)is a method for analysing the flow of information within an
organization using data flow diagrams.
Specification documents created in requirement analysis phase are used as input to conceptual schema
design phase. Structured data analysis (systems analysis) consists of
Validation –
Sorting –
Summarization(statistical) or (automatic) –
Aggregation –Analysis –
Reporting –
Classification
SSADM techniques Three most important techniques that are used in SSADM are as follows:
Logical design
Physical Design
Implementation
Physical Design stage has only one purpose: to maximize database efficiency.
This means finding ways to speed up the performance of the RDBMS. Manipulating certain database
design elements can speed up the two slowest operations in an RDBMS: retrieving data from and
writing data to a database.
1. Implementation
2. Monitoring, Modification, and Maintenance occur after database design is complete.
IV. Implementation
During the implementation stage of the DBLC, the tables developed in the ER diagram (and
subsequently normalized) are converted into SQL statements. These SQL statements are then executed
in the RDBMS to create a database. By this stage in the database life cycle, the System Administrator
has installed and configured an RDBMS.
RDBMS usually provides utilities to help monitor database functionality and security.
Database modification involves adding and deleting records, importing data from other systems (as
needed), and creating additional tables, user views, and other objects and tools.
DATABASE DESIGN:
Database designing
Logical model – This stage is concerned with developing a database model based on
requirements. The entire design is on paper without any physical implementations or specific
DBMS considerations.
Physical model – This stage implements the logical model of the database taking into account
the DBMS and physical implementation factors.
Implementation
Data conversion and loading – this stage of relational databases design is concerned with
importing and converting data from the old system into the new database.
Testing – this stage is concerned with the identification of errors in the newly implemented
system. It checks the database against requirement specifications.
RESULT:
Thus the various concepts such as Problem definition, Requirement analysis, Scope
and Constraints involved in Database Development Life Cycle has been studied.
EX. NO: 2 IMPLEMENT THE DATABASE USING SQL DATA DEFINITIONLANGUAGE
DATE:
AIM To create a database using SQL Data Definition Language using SQL queries.
PROCEDURE
DDL or Data Definition Language consists of the SQL commands that can be used to define
the database schema
DDL is set of SQL commands used to create, modify, and delete the structure of database
objects in the database but not data.
DDL changes structure of table like creating a table, deleting a table, altering a table, etc.
All the command of DDL are auto-committed that means it permanently save all the changes.
CREATE: This command is used to create the database or its objects (like table, index,
function, views, store procedure, and triggers).
DROP: This command is used to delete objects from the database.
ALTER: This is used to alter the structure of the database.
TRUNCATE: This is used to remove all records from a table, including all spaces
RENAME: This is used to rename an object existing in the database.
Example creates a table called "Persons" that contains five columns: PersonID, LastName, FirstName,
Address, and City:
Example 1
CREATETABLE Persons
( PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)
Example 2
Example
c. SQL ALTER Command: It is used to alter the structure of the database. This will modify the
characteristics of an existing attribute or to add a new attribute.
"Persons" table:
ID LastName FirstName Address City
d. SQL TRUNCATE:
The TRUNCATE TABLE statement is used to delete the data inside a table, but not the table
itself. It is used to delete all the rows from the table and free the space containing the table.
Syntax:
Example:
e. SQL RENAME
Database user can easily change the name of the table by using the RENAME TABLE and ALTER
TABLE statement in SQL. This helps in changing the name of the table.
Syntax:
Suppose, you want to change the above table name Cars into "Car_2021_Details".
RESULT:
Thus the Database has been created using Data Definition Language using SQL queries.
EX. NO: 3 IMPLEMENT DATABASE USING SQL DATA DEFINITION WITH VIEWS
DATE:
AIM: To Implement the database using SQL Data definition with Views
VIEWS DESCRIPTION:
A database view is a logical or virtual table based on a query. Views are queried just
like tables.
View is a virtual table based on the result-set of an SQL statement. A view also contains rows
and columns
To create the view, we can select the fields from one or more tables present in database.
A view can either have specific rows based on certain condition or all the rows of a
table. A DBA or view owner can drop a view with the DROP VIEW command.
TYPES OF VIEWS
• Updatable views – Allow data manipulation
• Read only views – Do not allow data manipulation
Example 1:
Student_Marks
1. Creating view:
A view can be created using CREATE VIEW statement. Create a view from a single table or multiple
tables.
Syntax:
In this example, we create a View named DetailsView from the table Student_Detail.
Query:
Just like table query, we can query the view to view the data.
Output:
NAME ADDRESS
Stephan Delhi
Kathrin Noida
David Ghaziabad
View from multiple tables can be created by including multiple tables in SELECT statement.
In this, view is created named MarksView from two tables Student_Detail and Student_Marks.
Query:
4. Deleting View - A view can be deleted using the Drop View statement.
RESULT:
Thus the Views using SQL has been executed using DDL and DML statements.
EX. NO: 4 QUERY THE DATABASE USING SQL
MANIPULATION DATE:
AIM:
To Query the database using SQL Manipulation i.e. Data Manipulation Language (DML)
Commands.
DESCRIPTION:
DML commands are SQL commands, used to manipulation of data i.e., modify
the data present in the database
It is responsible for all form of changes in the database.
The command of DML is not auto-committed that means it can't permanently save
all the changes in the database. They can be rollback.
a. SQL INSERT: SQL INSERT statement is used to insert a single or multiple data into row of a
table.
Syntax:
TABLE_NAME
Query: INSERT INTO EMPLOYEE VALUES (6, 'Marry', 'Canada', 600000, 48);
Output:
To insert partial column values, you must have to specify the column names.
Syntax
Query
INSERT INTO EMPLOYEE (EMP_ID, EMP_NAME, AGE) VALUES (7, 'Jack', 40);
Output: After executing this query, the table will look like:
b. SQL UPDATE:
This command is used to update or modify the value of a column in the table.
SQL UPDATE statement is used to modify the data that is already in the database.
The condition in the WHERE clause decides that which row is to be updated.
Syntax:
UPDATE table_name
[WHERE CONDITION]
Sample Table:
EMPLOYEE
Update column EMP_NAME and set the value to 'Emma' in the row where SALARY is 500000.
SET column_name =
Query
UPDATE EMPLOYEE
WHERE SALARY =
500000;
Output: After executing this query, the EMPLOYEE table will look like:
If you want to update multiple columns, you should separate each field assigned with a comma.Syntax
UPDATE table_name
WHERE condition;
Query
UPDATE EMPLOYEE
WHERE EMP_ID = 5;
Output
SET EMP_NAME =
'Harry';
Output
Syntax:
Example :
If you don't specify the WHERE condition, it will remove all the rows from the table.
Delete the row from the table EMPLOYEE where EMP_NAME = 'Kristen'. This will delete only
the fourth row.
Query
WHERE EMP_NAME =
'Kristen';
Output: After executing this query, the EMPLOYEE table will look like:
Delete the row from the EMPLOYEE table where AGE is 30.
Query
Delete all the row from the EMPLOYEE table. After this, no records left to display. The EMPLOYEE
table will become empty.
Syntax
or
Query
Output: After executing this query, the EMPLOYEE table will look like:
SELECT:
Example: EMPLOYEE
EMPLOYEE;
EMP_NAME SALARY
Kristen 150000
Russell 200000
Angelina 600000
Robert 350000
Christian 260000
To fetch all the fields from the EMPLOYEE table, use the following query:
Output
RESULT:
Thus, SQL Data Manipulation Language (DML) Commands for Querying the database
has been executed.
EX. NO: 5 CREATION OF A DATABASE USING SQL QUERIES DDL,
DML DATE:
AIM To create a database and to retrieve the information from the database using SQL queries.
CREATE
Table created
Sql> desc
student;
ALTER
MODIFY
TRUNCATE
Table truncated
SQL> select * from student;
No rows selected
DROP
; Table altered
DML COMMANDS
INSERT
1 row created
1 row created
1 row created
01 Manoj 99 IT 18
02 Ramana 98 IT 19
03 Samy 90 CSE 17
04 Prabha 99 CSE 16
UPDATE
1 row updated
01 Manoj 99 IT 18
02 Ramana 98 IT 19
03 Samy 90 CSE 17
04 Prabha 99 CSE 18
DELETE
1 rows deleted
01 Manoj 99 IT 18
02 Ramana 98 IT 19
04 Prabha 99 CSE 18
RESULT
Thus the creation of database and the SQL queries to retrieve information from the
database has been implemented using DDL and DML statements.
EX. NO : 6a SQL PROGRAMMING USING FUNCTIONS
DATE:
FUNCTION DESCRIPTION:
Functions are subprograms return a value. PL/SQL Function is very similar to PL/SQL
Procedure. The main difference between procedure and a function is, a function must always return
a value, and procedure may or may not return a value.
To create a function to return the total number of users in the user1 table.
Function Syntax:
Return datatype
is
[declaration_section]
Begin
Executable-section
Return function_value
End;
values(105,’Rubika’);
Select * from user1
ID NAME
101 Rahul
102 Risha
103 Rithu
104 Roja
105 Rubika
CREATE FUNCTION:
FUNCTION CALL:
DECLARE
c number(2);
BEGIN
c := totalCustomers();
dbms_output.put_line('Total no. of Customers: ' || c);
END;
/
Output:
Total no. of Users: 5
Statement processed.
RESULT:
Thus the SQL Programming Functions was executed and output was verified.
EX. NO: 6b FUNCTIONS IN SQL PROGRAMMING
DATE:
DESCRIPTION: To perform the addition of two numbers using Functions in SQL Programming
FUNCTION CREATION
DECLARE
n3 number(2);
BEGIN
n3 := add(11,22);
dbms_output.put_line('Addition is: ' ||
n3); END;
/
OUTPUT:
Addition is: 33
Statement processed.
RESULT:
Thus Function for addition of two numbers using SQL Programming was executed.
EX. NO: 7 QUERYING/MANAGING THE DATABASE USING SQL PROGRAMMING
DATE: FUNCTIONS
DESCRIPTION: To create a function for deposit and withdrawal of money from an account in a
bank management system this uses bank table.
TABE CREATION:
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created
PROGRAM:
return number is
b number;
begin
b:=b-amt;
else
dbms_output.put_line('can not
return b;
end;
/
Function created
declare
n number;
begin
n:=withdraw(100,20000);
end
Statement processed.
select * from bank_acc;
declare
n number;
begin
n:=withdraw(101,20000);
end
/
Statement processed.
DEPOSIT FUNCTION:
Create a function for depositing money to an account in a bank
b number;
begin
b:=b+amt;
return b;
end
/
Function created
declare
n number;
begin
n:=deposit(104,5000);
end
Statement processed.
RESULT:
Thus the Function for deposit and withdrawal of money in an account in a Bank Management
System was successfully executed.
EX. NO: 8 SQL PROGRAMMING PROCEDURES
DATE:
AIM:
To write a simple procedure to perform simple insertion operation Using SQL Programming
DESCRIPTION PROCEDURE:
Procedures are subprograms do not return a value directly; mainly used to perform an action.
PL/SQL Procedure is a PL/SQL block which performs one or more specific tasks. The procedure
contains a header and a body.
SYNTAX:
PROCEDURE CREATION:
BEGIN
greetings;
END;
Table Description:
desc user1;
Table Column Data Type Length Precision Scale Primary Key Nullable
USER1 ID Number - 10 0 1 -
PROCEDURE CREATION:
is
begin
end;
Output:
Procedure created.
PROCEDURE CALL:
BEGIN
insertuser(101,'Rahul');
END;
/
OUTPUT:
Statement processed.
ID NAME
101 Rahul
ID NAME
101 Rahul
102 Risha
103 Rithu
104 Roja
105 Rubika
DROP PROCEDURE:
Syntax:
DROP PROCEDURE
insertuser
DROP PROCEDURE
insertuser; Output:
Procedure dropped.
RESULT:
Thus the Procedure for simple insertion operation Using SQL Programming was successfully
executed.
EX. NO: 9 QUERYING/MANAGING THE DATABASE USING SQL
PROGRAMMING DATE: PROCEDURES
DESCRIPTION:
To create a procedure for deposit and withdrawal of money in an account in a bank table
Table Creation:
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
Create a procedure for deposit & withdrawal of money in account in a Bank table.
as
balance number;
begin
balance:= balance+amount;
acc_no=n; commit;
balance:=balance-amount;
if balance<1000 then
balance); else
acc_no=n; commit;
end if;
end;
Procedure created.
PROCEDURE CALL - DEPOSIT
begin
bank_pro(1,40000,100);
end;
/
Balance after deposition is 90000
Statement processed.
begin
bank_pro(2,1500,102);
end;
OUTPUT:
bank_pro(2,1500,103);
end;
OUTPUT:
RESULT:
TRIGGER DESCRIPTION:
SYNTAX:
Create trigger trigger name
BEFORE | AFTER
ON table name
FOR EACH
ROW BEGIN
Executable-statements
END;
Example:
Create a trigger so that the total and average of specified marks is automatically calculated whenever
a record is inserted.
Database creation:
create table student(sid number(4), name varchar(30), sub1 number(2), sub2 number(2),
sub3 number(2), total number(3), per number(3));
Table Description:
Desc student;
Before Trigger Execution: Inserting Values in table:
1 row(s) inserted.
CREATING TRIGGER
before insert
on
Student
Begin
Student.per = Student.total/3;
end;
/
OUTPUT: Trigger Created.
select * from
student; OUTPUT:
RESULT:
Thus the trigger while insert or update or delete operations are performed on the table
student was successfully executed and output was verified
EX. NO: 11 DATABASE DESIGN USING CONCEPTUAL MODELING (ER-EER)
AIM:
DESCRIPTION:
ER model
ER model stands for an Entity-Relationship model. It is a high-level data model. This model is
used to define the data elements and relationship for a specified system.
It develops a conceptual design for the database. It also develops a very simple and easy
to design view of data.
In ER modeling, database structure is portrayed as a diagram called entity-relationship
diagram.
In this database, the student will be an entity with attributes like address, name, id, age, etc. The
address can be another entity with attributes like city, street name, pin code, etc and there will be
a relationship between them.
Component of ER Diagram
The database can be represented using the notations, and these notations can be reduced to a collection
of tables.
In the database, every entity set or relationship set can be represented in tabular form.
TABLE CREATION
CREATE TABLE SALESMAN
(SALESMAN_ID NUMBER
(4),
NAME VARCHAR2 (20),
CITY VARCHAR2 (20),
COMMISSION VARCHAR2 (20),
PRIMARYKEY (SALESMAN_ID));
CREATE TABLE
CUSTOMER1 (CUSTOMER_ID
NUMBER (4),
CUST_NAME VARCHAR2 (20),
CITY VARCHAR2 (20),
GRADE NUMBER (3),
PRIMARY KEY (CUSTOMER_ID),
SALESMAN_ID REFERENCES SALESMAN (SALESMAN_ID) ON DELETE SET NULL);
TABLE DESCRIPTION:
RESULT:
Thus the mapping from a ER-EER Model to Relational Database in a Database Design Using
Conceptual Modeling was done successfully.
EX. NO: 12 DATABASE DESIGN USING NORMALIZATION
DATE:
AIM:
DESCRIPTION:
NORAMALIZATION OF TABLE
Database normalization is the process of removing redundant data from tables in order to improve
storage efficiency, data integrity, and scalability
2NF A relation will be in 2NF if it is in 1NF and all non-key attributes are fully
functional dependent on the primary key.
4NF A relation will be in 4NF if it is in Boyce Codd's normal form and has
no multi-valued dependency.
5NF A relation is in 5NF. If it is in 4NF and does not contain any join
dependency, joining should be lossless.
1. FIRST NORMAL FORM
The decomposition of the EMPLOYEE table into 1NF has been shown below:
14 John 7272826385 UP
14 John 9064738238 UP
20 Harry 8574783832 Bihar
12 Sam 7390372389 Punjab
12 Sam 8589830302 Punjab
Example 1:
In Second normal form, every non-prime attribute should be fully functionally dependent on prime
key attribute. That is, if X → A holds, then there should not be any proper subset Y of X, for which Y
→ A also holds true.
In Student_Project relation that the prime key attributes are Stu_ID and Proj_ID.
According to the rule, non-key attributes, i.e. Stu_Name and Proj_Name must be dependent upon
both and not on any of the prime key attribute individually.
But Stu_Name can be identified by Stu_ID and Proj_Name can be identified by Proj_ID
independently. This is called partial dependency, which is not allowed in Second Normal
Form.
Example: 2
TEACHER table
TEACHER_SUBJECT table:
TEACHER_ID SUBJECT
25 Chemistry
25 Biology
47 English
83 Math
83 Computer
A relation will be in 3NF if it is in 2NF and not contain any transitive partial dependency.
If there is no transitive dependency for non-prime attributes, then the relation must be in third
normal form.
For a relation to be in Third Normal Form, it must be in Second Normal form and must satisfy −
Example:1
In the above Student_detail relation, Stu_ID is the key and only prime key attribute.
City can be identified by Stu_ID as well as Zip itself. Neither Zip is a superkey nor is City a
prime attribute. Additionally, Stu_ID → Zip → City, so there exists transitive dependency.
To bring this relation into third normal form, we break the relation into two relations as follows −
Non-prime attributes: In the given table, all attributes except EMP_ID are non-prime.
Here, EMP_STATE & EMP_CITY dependent on EMP_ZIP and EMP_ZIP dependent on EMP_ID.
The non-prime attributes (EMP_STATE, EMP_CITY) transitively dependent on super key(EMP_ID).
It violates the rule of third normal form. That's why we need to move the EMP_CITY
and EMP_STATE to the new <EMPLOYEE_ZIP> table, with EMP_ZIP as a Primary
key.
After 3rd Normalization
EMPLOYEE table:
EMPLOYEE_ZIP table:
BCNF states that For any non-trivial functional dependency, X → A, X must be a super-key.
Zip → City
AIM:
DESCRIPTION:
Object Query Language (OQL) is a version of the Structured Query Language. Like
SQL, OQL is a declarative (not procedural) language
Object Query Language is a query language standard for object-oriented databases modeled
after SQL and developed by the Object Data Management Group.
OQL is the way to access data in an O2 database. OQL is a powerful and easy-to-use SQL-
like query language with special features dealing with complex objects, values and methods.
OQL is an attempt by the OO community to extend languages like C++ with SQL-
like, relation-at-a-time dictions.
create a table
create table
database_name.table_name (
column_name [constraints ] [default ] ,
[ column_name [ constraints ] [default ] , ]
[ additional_columns ]
[ unique ( column_name ) , ]
[ counter ( column_name ) ,
]
[ timestamp ( column_name ) ]
);
Example 1
Gender text,
Age int,
unique ( EmployeeID )
);
If no value is inserted into the Department column for a given record it takes the value "Sales".
Example 2
Skills text,
Gender text,
Age int
);
insert into
staff.managers (
EmployeeID, Name, Department, Gender, Age
)
values
(
1, "Matt", "Development", "M", 28
);
insert into
staff.managers values
(
2, "Jane", "Customer Services", "F", 27
);
SELECTING DATA FROM A TABLE
Syntax:
select comma_separated_column_list
from database_name.table_name
[ where conditional_test ]
The * symbol can be used in a select statement to return all the columns of the table.
Output:
EmployeeID=1;
Name='Matt';
Department='Development';
Gender='M';
Age=28;
EmployeeID=2;
Name='Jane';
Department='Customer Services';
Gender='F';
Age=27;
( 2 record(s) : Transaction complete )
"Development";
Output:
EmployeeID=1;
Name='Matt';
( 1 record(s) : Transaction complete )
UPDATE RECORDS IN TABLE
Syntax
[ where conditional_test ] ;
If the update statement is used without a where condition, all records are updated.
Example: Updates Age column of staff.managers table for any records where Name="John"
Update staff.managers
set Age=30
where Name="John";
Use the show keyword to list the databases, columns, or tables or the current service.
Syntax
show databases ;
show databases;
databases = [ 'staff'
Example - Deletes all records from the staff.contractors table where Name="James".
delete from
staff.contractors where
Name="Jane";
RESULT:
Thus the Querying of Object-Relational database using Objet Query language was executed
EX. NO: 14 OBJECT FEATURES OF SQL-UDTS AND SUB-TYPES, TABLES USING
UDTS, DATE: INHERITANCE, METHOD DEFINITION
AIM:
To Study about the various Object Features such as SQL-UDTS And Sub-Types, Tables
Using UDTS, Inheritance, Method Definition etc.,
DESCRIPTION
as (...)
TYPE INHERITANCE
(20)); create type Teacher under Person (salary integer, department varchar
(20));
Both Student and Teacher inherit the attributes of Person—namely, name and address. Student
and Teacher are said to be subtypes of Person, and Person is a supertype of Student, as well as of
Teacher
Multiple inheritance:
Agent and
Customer.
Objects can also be attributes of other objects. The Person type has been created to include an address
UDT. After the types are created a typed table of Agent objects is created and a new row is inserted
into the table.
insert into Agents values ('001', 'John Smith', Address('123 Main', 'Lal street)
(a) Using UDTs as types for attributes such as Address and Phone
(d) Creating tables based on some of the UDTs, and illustrating table inheritance,
RESULT:
Thus various Object Features such as SQL-UDTS And Sub-Types, Tables Using
UDTS, Inheritance, Method Definition have been studied.
EX. NO: 15 DEVELOP DATABASE APPLICATIONS USING IDE (NETBEANS)
DATE:
AIM:
To Develop Database Applications Using IDE (Netbeans) To Connect Java Program With
MS-Access Using JDBC Connectivity
JDBC DESCRIPTION
Java has defined its own API (JDBC API) that uses JDBC drivers (written in Java language).
JDBC API is used to handle database using Java program and can perform the following
activities:
Step 1: Open Microsoft Access and select Blank database option and give the database name as File
name option
Step 2: Create a table and insert your data into the table
Step 3: Save the table with the desired name;, we save the following records with the table
name student.
Step 7: Make your desired Data Source Name and then click on the Select option, for example in this
article we use the name mydsn
Step 8: Now you select your data source file for storing it and then click ok and then click on Create
and Finish
code Test.java
import java.sql.*;
class TestDB
{
public static void main(String ar[])
{
Try
{
String url="jdbc:odbc:mydsn";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection(url);
Statement st=c.createStatement();
ResultSet rs=st.executeQuery("select * from
login"); while(rs.next())
{
System.out.println(rs.getString(1) + " " + rs.getString(2)+ " " rs.getString(2));
}
}
catch(Exception ee){System.out.println(ee);
} } }
RESULT:
Thus the Database Applications Using IDE (Netbeans) To Connect Java Program With MS-
Access Using JDBC Connectivity is executed.
CONTENT BEYOND THE LAB SYLLABUS
Ex.No :1
NOSQL Commands using MONGODB,CASSANDRA,HIVE,ORIENTDB
Date:
A) MONG
ODBAIM
:
To write NOSQL QUERIES to understand the concept of Open Source Database
ManagementSystem such as MongoDB.
PROCEDURE:
Step 1: Start the MongoDB Server (Mongos).
Step 2: Start the Client (Mongod)
Step 3: Perform the MongoDB Curd Operations such as (Create,
Update,Read,Delete).Syntax: To Create/Select a Collection: USE
DATABASE_NAME.
Syntax: To Insert: DB.COLLECTION_NAME.INSERT(DOCUMENT).
Syntax: To Update: DB.COLLECTION_NAME.UPDATE(<FILTER>, <UPDATE> )
Syntax: To Display/Search: DB.COLLECTION_NAME.FIND ()
Syntax: To Delete: DB.COLLECTION_NAME.REMOVE (DELETION_CRITERIA)
Create :
> use mca;
switched to
db mca
Insert:
Update:
Delete:
Find:
> db.mca.studentInfo.find({})
RESULT:
AIM:
To write NOSQL QUERIES to understand the concept of Open Source Database Management
System such as CASSANDRA.
PROCEDURE:
Create KeySpace:
cqlsh>use gct;
Create Table
cqlsh:gct>CREATE TABLE VVT(Id int PRIMARY KEY,name text,city text,fees varint);
Alter Table
cqlsh:gct>ALTER TABLE VVT ADD email text;
View Table
cqlsh:gct> select * from vvt;
id | city | email | fees | name
+ + + + (0 rows)
Alter Table
cqlsh:gct> ALTER TABLE VVT DROP
email;cqlsh:gct> select * from vvt;
Truncate Data
cqlsh:gct> TRUNCATE VVT;
cqlsh:gct> INSERT INTO VVT(Id, fees,name,city)VALUES(1,5000, 'Surya
S','Namakkal');cqlsh:gct> select * from vvt;
Delete Data
cqlsh:gct> DELETE FROM VVT WHERE
id=3;cqlsh:gct> select * from vvt;
RESULT:
AIM:
To write NOSQL QUERIES to understand the concept of Open Source Database Management System
such as HIVE.
PROCEDURE:
Step 1: Start the Hadoop Cluster from sbin Folder (Run start-dfs, start-yarn).
Step 2: Start the derby node using the command(StartNetworkServer -h
0.0.0.0)Step 3: Then Start the Hive.(Hive command)
Step 4: Hive data types are categorized in numeric types, string types, misc types, and complex types.
Step 5: Syntax to Create a Database.first we have to check weather the DB is Already Exist or Not for
thatshow database;
Step 6: if Not Exist Create Database Database_Name;
Step 7: Perform Some Table Operations in Hive such as Create, Alter, Drop Table.
Step 8: Finally Partitioning the Hive.
hive> show
databases;OK
Default
Time taken: 0.271 seconds, Fetched: 1
row(s)hive> create database demo;
hive> show
databases;OK
Time taken: 0.215 seconds
hive> create a database if not exists
demo;OK
Time taken: 0.107 seconds
hive>create database demo WITH DBPROPERTIES('creator' = 'Natz', 'date' = '2019-06-03');
OK
Time taken: 2.389 seconds
hive> create table demo.employee (Id int, Name string , Salary float);
OK
Time taken: 0.461 seconds
hive> select * from
demo.employee;OK
1 “SURYA S” 30000.0
2 “SUNDAR S” 40000.0
3 “SURESH C” 50000.0
4 “MUNISH” 90000.0
hive> describe
demo.employeeOK
id int
Name
string
salary
fl
oat
Time taken: 0.215 seconds
hive> Alter table employee rename to
employee_data;OK
Time taken: 6.06 seconds
hive> describe
employee_data;OK
id int
Name
string
salary
fl
oat
Time taken: 0.275
secondshive> show
tables;
OK
Employee
Employee_d
ata
Time taken: 0.098 seconds, Fetched: 2 row(s)
int
Name
string
salary
floatage
Time taken: 0.275
secondshive> show
tables;
OK
employee
employee_d
ata
Time taken: 0.098 seconds, Fetched: 2 row(s)
Static Partitioning
hive> describe
student;OK
id int
name string
age int
institute course
course string
# Partition Information
# col_name data_type comment
Course string
Time taken: 1.054 seconds, Fetched: 10 row(s)
RESULT:
AIM:
To write NOSQL QUERIES to understand the concept of Open Source Database Management
System such as OrientDB Graph.
PROCEDURE:
Step3: Choose the Database and enter the username and password for the OrientDB
Step5: Create a Class, Node, Edges and Insert the fields Finally connect the graph display the output.
QUERIES
RESULT:
AIM:
PROCEDURE:
Server.Step 2: Create a
Database.
the table.
Step 6: In the output screen Select Form Editor output will be displayed.
QUERIES WITH EXECUTION:
CREATE TABLE
spatial1.restaurants (name
VARCHAR(20),
location GEOMETRY NOT
NULL,SPATIAL
INDEX(location)
);
Thus the above program for spatial data storage and retrieval in MYSQL executed successfully.