Dbmsfinal 2022ucm2342
Dbmsfinal 2022ucm2342
Dbmsfinal 2022ucm2342
Technology
DBMS Final Lab Report
1
2
INDEX
3
Exercise 1:
Data Definition Language (DDL) and Data Manipulation Language (DML) commands of
base tables and views.
5
Exercise 2:
High level programming language extensions.
(c) FUNCTIONS:
❖ A function is a program that might perform an action and does return a
value. The function is a subprogram that computes a value.
6
❖ Like a procedure, a function has two parts: 1. The specification 6 2. The
body The Specification:
❖ The function specification begins with the keyword FUNCTION and ends
with the RETURN clause, which specifies the data type of the return value.
❖ Parameter declaration are optional. Functions that take no parameters
are written without parentheses. The Body:
❖ The function body begins with the keyword IS (or AS) and ends with
keyword END followed by an optional function name.
❖ The function body has three parts: 1. A Declarative part. 2. An Executable
part. 3. An Exception-handling part (Optional).
❖ The declarative par contains local declarations, which are placed between
the keywords IS and BEGIN.
❖ The keyword DECLARES is not used.
❖ The executable part contains statements, which are placed between the
keywords BEGIN, and EXCEPTION (or END).
7
Exercise 3:
XAMPP Installation Steps and create CSAI database with Sailor-Boats- Reserves Tables.
8
9
Step 3: In the XAMPP control panel, start MySQL and Apache.
Step 4: Go to phpMyAdmin.
10
Step 5: Create a new Database and name it ‘CMCT Database’.
Step 6: After creating the database, Create three tables namely ‘Sailors’, ‘Boats’ and
‘Reserves’. After creating each table, enter respective attributes provided by the
instructor.
11
12
13
Step 7: Now select the SAILORS table and select the column (here, sid). Then select
primary to set primary key. Set bid as primary key in the BOATS table.
14
Step 8: Now go to the relation view and set bid and sid in reserves table as foreignkeys.
15
Exercise 4:
Connecting XAMPP with Python
1. Python in XAMPP
16
Output in XAMPP:
17
Exercise 5:
Answering Queries considering a given relational schema using SQL and relational
algebra.
18
19
Exercise 6:
Decomposing a Table, providing all Functional dependencies and answering queries
related to the data.
20
21
Exercise 7:
Normalizing and Decomposing a given table.
22
23
Exercise 8:
Installing Java and connecting with XAMPP.
STEP 1: INSTALL APACHE IDE, JAVA Connector JAR File, JAVA Development Kit (JDK)
STEP 2: OPEN THE APACHE INSTALLER AND INSTALL APACHE. AFTER INSTALLING GO TO FILE
-> NEW PROJECT -> JAVA WITH ANT -> JAVA APPLICATION
STEP 4: Copy the code for connection, display, insertion and deletion and make the
appropriate changes such as changing the name of your database, name of attributes etc.
1) Connection -> Establishing JAVA – XAMPP CONNENCTION
package job;
import java.sql. *;
import java.util.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
24
// connect way #1
String url1 = "jdbc:mysql://localhost:3306/cmct";
String user = "root";
String password = "";
conn1 = DriverManager.getConnection(url1, user, password);
if (conn1 != null) {
System.out.println("Connected to the database cmct");
}
}
catch (SQLException ex) {
System.out.println("An error occurred. Maybe user/password is invalid");
ex.printStackTrace();
}
finally {
if (conn1 != null) {
try {
conn1.close();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
}
}
}
CONNECTION SUCCESSFUL !
package jdbc;
import java.sql.*;
25
import java.util.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import com.mysql.jdbc.Statement;
} catch (Exception e) {
e.printStackTrace();
}
}
}
26
import java.util.HashMap;
ResultSet rs = stmt.executeQuery(QUERY);
while(rs.next()){
//Display values
System.out.print("SID: " + rs.getInt("SID"));
System.out.print(", Rating: " + rs.getInt("Rating"));
System.out.print(", Sname: " + rs.getString("Sname"));
System.out.println(", DOB: " + rs.getString("DOB"));
}
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
27
import java.sql.SQLException;
import java.util.Properties;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
28
5) DELETE -> Deleting a record with SID = 10
CODE : (DELETION)
package jdbc;
import java.sql.*;
import java.util.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
29
System.out.print("SID: " + rs.getInt("SID"));
System.out.print(", Rating: " + rs.getInt("Rating"));
System.out.print(", Sname: " + rs.getString("Sname"));
System.out.println(", DOB: " + rs.getString("DOB"));
}
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Before deleting the record :
30
Exercise 9:
Designing and decomposing a table to normalize it.
31
Exercise 10:
Creating a design to BCNF implement the task in JAVA.
EMP. Car- P-
_No nam arkin
e area
101 Nano A
102 Maruti- B
SWIFT
103 Benz C
104 Nano A
32
Table Used: Salary
102
103
104
C O D E :
import java.sql.Connection;
import
java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
33
public class EmployeeCarQueries {
34
public static void main(String[] args) {
DriverManager.getConnection(jdbcUrl, username,
password)) {
= cp.EMP_No " +
s.EMP_No " +
s.Salary_Scale = 'Scale3';";
35
PreparedStatement statement =
connection.prepareStatement(query);
ResultSet resultSet =
statement.executeQuery();
while (resultSet.next()) {
System.out.println("Name: " +
resultSet.getString("NAME"));
resultSet.getString("FATHER_NAME"));
resultSet.getInt("EMP_No"));
System.out.println("DOB: " +
resultSet.getString("DOB"));
36
System.out.println("Sex: " +
resultSet.getString("SEX"));
resultSet.getString("MOTHER_TONGUE"));
System.out.println("City: " +
resultSet.getString("CITY"));
System.out.println("Street: " +
resultSet.getString("STREET"));
System.out.println("State: " +
resultSet.getString("STATE"));
System.out.println();
} catch (SQLException e) {
e.printStackTrace();
37
of particular amount.
CODE:
import java.sql.Connection;
import
java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
url-here";
DriverManager.getConnection(jdbcUrl, username,
38
password)) {
39
String query = "SELECT cp.Car_name " +
s.EMP_No " +
PreparedStatement statement =
connection.prepareStatement(query);
ResultSet = statement.executeQuery();
while (resultSet.next()) {
System.out.println(resultSet.getString("Car_name"
));
40
}
} catch (SQLException e) {
e.printStackTrace();
41