DBMS LAB MANUAL
DBMS LAB MANUAL
To Excel in the emerging areas of Computer Science and Engineering by imparting knowledge,
relevant practices and inculcating human values to transform the students as potential resources to
contribute innovatively through advanced computing in real time situations.
DM1. To provide strong fundamentals and technical skills for Computer Science applications
through effective teaching learning methodologies.
DM2. To transform lives of the students by nurturing ethical values, creativity and novelty to
become Entrepreneurs and establish start-ups.
DM3. To habituate the students to focus on sustainable solutions to improve the quality of life
and the welfare of the society.
DM4. To enhance the fabric of research in computing through collaborative linkages with
industry and academia.
DM5. To inculcate learning of the emerging technologies to pursue higher studies leading to
lifelong learning.
COURSE OBJECTIVES AND OUTCOMES
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:
OUTCOMES:
CO’s
EX NO DATE PO’s & PSO’s SIGN
TITLE MAPPED MARKS
MAPPED
VIEWS, SEQUENCES,
3 SYNONYMS
PROCEDURES AND
5 FUNCTIONS
TRIGGERS
6
EXCEPTION HANDLING
7
DATABASE DESIGN USING ER
8 MODELING, NORMALIZATION
DATABASE CONNECTIVITY
9 WITH FRONT END TOOLS
CO’s
EX NO DATE PO’s & PSO’s SIGN
TITLE MAPPED MARKS
MAPPED
POPULATING DATABASE IN
11 QUERY
AIM:
To design and implement a database in MySQL using Structured Query Language
commands
S YNTAX:
INSERT:
SELECT:
UPDATE:
DELETE:
TCL Commands
COMMIT
Syntax:
Commit:
Syntax:
ROLLBACK TO [SAVEPOINT] savepointname; Where,
SAVEPOINT:is optional and is used to rollback a partial transaction, as far the specified
savepoint.
Savepointname: is a savepoint created in current transaction.
SAVEPOINT
Syntax:
SAVEPOINT savepointname;
PROBLEM STATEMENT:
Customer browse the catalogue of books
Customers place the orders
Customers call the book store and give the ISBN of a book and quantity.
Store prepares a shipment that contains the books customers have ordered
TABLE FROM THE PROBLEM STATEMENT
1) Books
2) Customers
3) Orders
4) Order_list
[root@localhost ~]# service mysqld start
[root@localhost ~]# mysql
mysql> create database sheryl;
Query OK, 1 row affected (0.00 sec)
mysql> use sheryl;
Database changed
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| sheryl |
| test |
+--------------------+
4 rows in set (0.00 sec)
Table name: Books
mysql> Create table books(ISBN varchar(10) primary key, title varchar(30),
author char(10),Quan_instock int,price int ,pub_year date);
Query OK, 0 rows affected (0.01 sec)
Description of table
mysql> desc books;
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| ISBN | varchar(10) | NO | PRI | NULL | |
| title | varchar(30) | YES | | NULL | |
| author | char(10) | YES | | NULL | |
| Quan_instock | int(11) | YES | | NULL | |
| price | int(11) | YES | | NULL | |
| pub_year | date | YES | | NULL | |
+--------------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
Table name: Customers
mysql> create table customer(cust_id varchar(10) primary key, cust_name
varchar(20), cust_addr varchar(15), card_no varchar(15));
Query OK, 0 rows affected (0.01 sec)
Description of table
mysql> desc customer;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| cust_id | varchar(10) | NO | PRI | NULL | |
| cust_name | varchar(20) | YES | | NULL | |
| cust_addr | varchar(15) | YES | | NULL | |
| card_no | varchar(15) | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
Description of table
mysql> desc orders;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| order_no | varchar(10) | NO | PRI | NULL | |
| cust_id | varchar(10) | YES | | NULL | |
| order_date | date | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
Description of table
mysql> desc order_list;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| order_no | varchar(20) | NO | PRI | NULL | |
| ISBN | varchar(10) | YES | | NULL | |
| quantity | int(11) | YES | | NULL | |
| ship_date | date | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
1.Write a query for creating new table from existing table with all fields.
mysql> create table cust as select * from customer;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
Description of table
mysql> desc cust;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| cust_id | varchar(10) | NO | | NULL | |
| cust_name | varchar(20) | YES | | NULL | |
| cust_addr | varchar(15) | YES | | NULL | |
| card_no | varchar(15) | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
2.Write a query for creating new table from existing table with selected fields.
mysql> create table cust1 as select cust_id,cust_name from cust;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
Description of table
mysql> desc cust1;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| cust_id | varchar(10) | NO | | NULL | |
| cust_name | varchar(20) | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
3.Write a query to create new table from existing table without any record.
mysql> create table cust2 as select * from cust where 1>2;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
Description of table
mysql> desc cust2;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| cust_id | varchar(10) | NO | | NULL | |
| cust_name | varchar(20) | YES | | NULL | |
| cust_addr | varchar(15) | YES | | NULL | |
| card_no | varchar(15) | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
4. Alter the table books by increasing the field width of ISBN to 15.
mysql> desc books;
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| ISBN | varchar(10) | NO | PRI | NULL | |
| title | varchar(30) | YES | | NULL | |
| author | char(10) | YES | | NULL | |
| Quan_instock | int(11) | YES | | NULL | |
| price | int(11) | YES | | NULL | |
| pub_year | date | YES | | NULL | |
+--------------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
============================================================================
10. Drop customer_1 table.
13. Update the cust_addr as guindy for customer name raja in the Customer table.
mysql> select * from customer;
+---------+-----------+------------+---------+
| cust_id | cust_name | cust_addr | card_no |
+---------+-----------+------------+---------+
| 10 | Geetha | Medavakkam | C10 |
| 11 | Raja | Siruseri | C11 |
+---------+-----------+------------+---------+
2 rows in set (0.00 sec)
mysql> update customer set cust_addr='Guindy' where cust_name='Raja';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> rollback;
Query OK, 0 rows affected (0.01 sec)
SAVE POINT
mysql> rollback;
Query OK, 0 rows affected (0.00 sec)
INFERENCE:
RESULT:
EX NO: 2
DATE: SIMPLE QUERIES, NESTED QUERIES, SUB QUERIES AND JOINS
AIM: To execute database querying with Simple queries, Nested queries, Sub queries and Joins
Syntax:
SELECT:
Syntax 1:Select column name1,columnname2 from <table name>;
Syntax 2: select * from <tablename>;
Syntax 3: select * from <tablename> where <condition>;
Select_clause from_clause [where_clause][groupby_clause][having_clause][orderby_clause]
The SELECT clause defines the types of the objects or values returned by the
query.The FROM clause defines the scope of the query by declaring one or more identification
variables, which can be referenced in the SELECTand WHERE clauses. An identification variable
represents one of the following elements:
The abstract schema name of an entity
An element of a collection relationship
An element of a single-valued relationship
A member of a collection that is the multiple side of a one-to-many relationship
The WHERE clause is a conditional expression that restricts the objects or values retrieved
by the query. Although the clause is optional, most queries have a WHERE clause.
The GROUP BY clause groups query results according to a set of properties.
The HAVING clause is used with the GROUP BY clause to further restrict the query results
according to a conditional expression.
The ORDER BY clause sorts the objects or values returned by the query into a specified
order.
Subqueries with the SELECT Statement
SELECT column_name [, column_name ]FROM table1 [, table2 ]
WHERE column_name OPERATOR(SELECT column_name [, column_name ]
FROM table1 [, table2 ][WHERE])
Subqueries with the INSERT Statement
INSERT INTO table_name [ (column1 [, column2 ]) ]SELECT [ *|column1 [, column2 ]FROM table1 [, tabl
e2 ][ WHERE ]
Subqueries with the UPDATE Statement
UPDATE tableSET column_name = new_value[ WHERE OPERATOR [ VALUE ](SELECT COLUMN_NA
MEFROM TABLE_NAME)[ WHERE) ]
Subqueries with the DELETE Statement
DELETE FROM TABLE_NAME[ WHERE OPERATOR [ VALUE ](SELECT COLUMN_NAME
FROM TABLE_NAME)[ WHERE) ]
JOIN COMMANDS
INNER JOIN command returns the matching rows from the tables that are being joined.
LEFT OUTER JOIN command returns matching rows from the tables being joined and also non-
matching row from the left table in the result and places null values in the attributes that come
from the right side table.
RIGHT OUTER JOIN command returns matching rows from the tables being joined and also non-
matching row from the right table in the result and places null values in the attributes that come
from the left side table.
1. Find the names of all names in book relation eliminate duplicate.
mysql> select distinct author from books;
+----------+
| author |
+----------+
| David |
| James |
+----------+
3 rows in set (0.00 sec)
=============================================================================
2.display in the books table with attribute price multiplied by 10.
mysql> select price*10 from books;
+----------+
| price*10 |
+----------+
| 1200 |
| 1200 |
| 2000 |
+----------+
3 rows in set (0.00 sec)
============================================================================
3. Find all title for books whose author is james and price greater
Than 100.
mysql> select title from books where author='James'and price>100;
+-------------+
| title |
+-------------+
| Fairy Tales |
+-------------+
1 row in set (0.00 sec)
============================================================================
4. Find all isbn for books with book price between 150 and 200.
mysql> select isbn from books where price between 150 and 200;
+-------+
| isbn |
+-------+
| 1-103 |
| 2-203 |
+-------+
3 rows in set (0.00 sec)
=============================================================================
5. Find the names of customer whose name includes the character ‘e’ in the third position.
mysql> select cust_name from customer where cust_name like '__%';
+-----------+
| cust_name |
+-----------+
| Geetha |
+-----------+
1 row in set (0.00 sec)
=============================================================================
6. Find the names of customer whose address starts with substring ‘e’.
SALESMAN TABLE
salesman_id name city commission
----------- ---------- ---------- ----------
5001 James Hoog New York 0.15
5002 Nail Knite Paris 0.13
5005 Pit Alex London 0.11
5006 Mc Lyon Paris 0.14
5003 Lauson Hen San Jose 0.12
5007 Paul Adam Rome 0.13
ORDERS TABLE
CUSTOMER TABLE
1.Write a query to display all the orders from the orders table issued by the salesman 'paul adam'.
mysql>SELECT * FROM orders WHERE salesman_id = (select salesman_id FROM salesman
WHEREname='Paul Adam');
2.Write a query to display all the orders which values are greater than the average order value for
10th October 2012.
mysql>SELECT * FROM orders WHERE purch_amt > (select AVG(purch_amt) FROM orders
whereord_date ='10/10/2012');
3. Write a query to find the sums of the amounts from the orders table, grouped by date, eliminating
all those dates where the sum was not at least 1000.00 above the maximum amount for that date.
mysql>SELECT ord_date, SUM (purch_amt) FROM orders a GROUP BY ord_date HAVING SUM
(purch_amt) > (SELECT 1000.00 + MAX(purch_amt) FROM orders b WHERE a.ord_date =
b.ord_date);
4. Write a query to extract the data from the customer table if and only if one or more of the
customers in the customer table are located in London.
mysql>SELECT customer_id,cust_name, city FROM customer WHERE EXISTS (SELECT * FROM
customer WHERE city='London');
5.Write a query to find all the salesmen who worked for only one customer.
mysql>ELECT * FROM salesman WHERE salesman_id IN (SELECT DISTINCT salesman_id FROM
customer a WHERE NOT EXISTS (SELECT * FROM customer b WHERE a.salesman_id =
b.salesmanidAND a.cust_name<>b.cust_name));
6.Write a query to find all those customers who hold a different grade than any customer of the city
Dallas.
mysql>SELECT *FROM customer WHERE NOT grade = ANY (SELECT grade FROM customerWHERE
city='Dallas');
Table: Emp
Table:Depart
mysql> create table depart(deptno int,dname char(12),loc char(12));
Query OK, 0 rows affected (0.01 sec)
Table:Staff
mysql> create table staff(staff_id int primary key,staff_name char(10),expr
int,age int);
Query OK, 0 rows affected (0.00 sec)
Table:Book
Table:Issue
JOIN COMMANDS
EQUI-JOIN
Display the employee details, departments that the departments are same in both the emp and dept.
SELF JOIN
Write a Query to display employee names using Self Join
mysql> select distinct ename from emp x,depart y where x.deptno=y.deptno;
+---------+
| ename |
+---------+
| Arjun |
| Barath |
| Aparna |
+---------+
4 rows in set (0.00 sec)
SUB-QUERY (query within another query)
Update deptno by adding empno and keep that as deptno for employee 4.
mysql> update emp set deptno=( select sum(empno)from depart) where empno=4;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
INFERENCE:
RESULT:
EX NO: 3
DATE: VIEWS, SEQUENCES, SYNONYMS
AIM:
To implement and execute view, sequence and synonym in MySQL using Structured Query
Language commands
S YNTAX:
CREATE
[ALGORITHM = {MERGE | TEMPTABLE | UNDEFINED}]
VIEW [database_name].[view_name]
AS [SELECT statement]
index_col_name:
col_name [(length)] [ASC | DESC]
index_type:
USING {BTREE | HASH}
1)VIEWS:
Create a view using aggregate functions to calculate the No of years publish of the customer
3)INDEXES
To create an index on the Last Name column of the student table
CREATE INDEX:
mysql> create index lastname on student(name);
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
DROP INDEX:
mysql> drop index lastname on student;
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
INFERENCE:
RESULT:
EX NO: 4
IMPLICIT AND EXPLICIT CURSORS
DATE:
AIM:
SYNTAX:
Explicit Cursors:
mysql> delimiter $$
mysql> call curdemo(2)
-> $$
+------+
| name |
+------+
| shah |
+------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter $$
mysql> create procedure close_cursor(id int)
-> begin
-> declare name char(25);
-> declare cur1 cursor for select stu_name from student where stu_id =id;
-> open cur1;
-> fetch cur1 into name;
-> select name;
-> close cur1;
-> end $$
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter $$
mysql> call close_cursor(4);
-> $$
+------+
| name |
+------+
| maze |
+------+
1 row in set (0.00 sec)
RESULT:
EX NO: 5
DATE: PROCEDURES AND FUNCTIONS
AIM:
SYNTAX
CREATE
[DEFINER = { user | CURRENT_USER }]
PROCEDURE sp_name ([proc_parameter[,...]])
[characteristic ...] routine_body
CREATE
[DEFINER = { user | CURRENT_USER }]
FUNCTION sp_name ([func_parameter[,...]])
RETURNS type
[characteristic ...] routine_body
proc_parameter:
[ IN | OUT | INOUT ] param_name type
func_parameter:
param_name type
type:
Any valid MySQL data type
characteristic:
LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
| COMMENT 'string'
routine_body:
Valid SQL procedure statement
FUNTION SYNTAX:
CREATE
[DEFINER = { user | CURRENT_USER }]
FUNCTION sp_name ([func_parameter[,...]])
RETURNS type
[characteristic ...] routine_body
func_parameter:
param_name type
FACTORIAL OF GIVEN NUMBER
mysql> delimiter $$
mysql> CREATE PROCEDURE factorial(IN x INT)
-> BEGIN
-> DECLARE result INT;
-> DECLARE i INT;
-> SET result = 1;
-> SET i = 1;
-> WHILE i <= x DO
-> SET result = result * i;
-> SET i = i + 1;
-> END WHILE;
-> SELECT x AS Number, result as Factorial;
-> END;
-> $$
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
mysql> CALL getin('Boston');
+--------+-----------+--------+
| deptno | dname | loc |
+--------+-----------+--------+
| 40 | Operation | Boston |
+--------+-----------+--------+
1 row in set (0.00 sec)
INFERENCE:
RESULT:
EX NO: 6
TRIGGERS
DATE:
AIM:
TRIGGERS:
1) Trigger is a special type of procedure that the oracle executes when an insert,
modify or delete operation is performed against a given table.
2) It is a stored sub program associated with a table.
3) It is used to keep an audit trial of a table, to prevent invalid transaction, enforce
complex security authorization, to generate data automatically.
SYNTAX:
Syntax:
CREATE[DEFINER = { user | CURRENT_USER }]
TRIGGER trigger_name trigger_time trigger_event
ON tbl_name FOR EACH ROW trigger_stmt
Create a trigger to calculate the net salary and average salary of a employee in the employee table.
mysql> delimiter $$
mysql> CREATE TRIGGER before_emp_update
-> BEFORE UPDATE ON employees
-> FOR EACH ROW BEGIN
-> INSERT INTO emp_audit
-> SET action='update',
-> employeenumber=OLD.employeenumber,
-> lastname=OLD.lastname,
-> changedon = NOW();
-> END$$
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
mysql> update employees set lastname='Ivan' where employeenumber=102;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
INFERENCE:
RESULT:
EX NO: 7
EXCEPTION HANDLING
DATE:
AIM:
To implement and execute PROCEDURE that handles all types of exceptions in MySQL
Database using Procedural Language concepts.
The DECLARE….HANDLER statement specifies a handler that deals with one or more conditions. If one of
these conditions occurs, the specified statement executes. statement can be a simple statement such as SET
var_name = value, or a compound statement written using BEGIN and ENDThe handler_action value indicates
what action the handler takes after execution of the handler statement:
The condition_value for DECLARE ... HANDLER indicates the specific condition or class of conditions that
activates the handler:
1099 HY000 Table „%s‟ was locked with a READ lock and
can‟t be updated
1100 HY000 Table „%s‟ was not locked with LOCK
TABLES
1106 42000 Incorrect parameters to procedure „%s‟
1114 HY000 The table „%s‟ is full
Delayed insert thread couldn‟t get requested
1150 HY000
lock for table %s
1165 HY000 INSERT DELAYED can‟t be used with table
„%s‟ because it is locked with LOCK TABLES
1242 21000 Subquery returns more than 1 row
+----------+
| COUNT(*) |
+----------+
| 4 |
+----------+
1 row in set (0.00 sec)
INFERENCE:
RESULT:
EX NO: 8 DATABASE DESIGN USING ER MODELING, NORMALIZATION AIM:
DATE:
To implement. database design using ER modeling, normalization and implementation for
any application
ER- Diagram:
It is an Entity –Relationship diagram which is used to represent the relationship between different
entities. An entity is an object in the real world which is distinguishable from other objects. The
overall logical structure of a database can be expressed graphically by an ER diagram, which is built
up from following components.
Rectangles: represent entity sets.
Ellipses: represent attributes.
Diamonds: represent relationships among entity sets.
Lines: link attribute to entity sets and entity sets to relationships.
Mapping Cardinalities:
It expresses the number of entities to which another entity can be associated via a relationship set.
For a binary relationship set R between entity sets A and B. The Mapping Cardinalities must be one
of the following.
One to one
One to many
Many to one
Many to many
36
ER DIAGRAM
Produce the Third Normal Form of this document by normalization
0NF
ORDER(order#, customer#, name, address, orderdate(product#, description, quantity, unitprice))
1NF
ORDER(order#, customer#, name, address, orderdate)
ORDER_LINE(order#, product#, description, quantity, unitprice)
2NF
ORDER(order#, customer#, name, address, orderdate)
ORDER_LINE(order#, product#, quantity)
PRODUCT(product#, description, unitprice)
3NF
ORDER(order#, customer#, orderdate)
CUSTOMER(customer#, name, address)
ORDER_LINE(order#, product#, quantity)
PRODUCT(product#, description, unitprice)
INFERENCE:
RESULT:
EX NO: 9 DATABASE CONNECTIVITY WITH FRONT END TOOLS AIM
DATE:
:
To design and implement a database connectivity with front end tools for Book database
using Netbeans and mysql.
Steps:
Database Creation:
mysql>CREATE testdb;
mysql>USE testdb;
mysql>create table books(isbn varchar(20) primary key,title varchar(50),
edition varchar(20),price float(10,2));
mysql>create table authors(author_id int primary key,author_name
varchar(50));
mysql>create table book_by_author(isbn varchar(20),author_id int,foreign
key(isbn)references books(isbn),foreign key(author_id) references
authors(author_id));
Insertion:
msql>insert into books values('123456','Discrete Math','Second',56.78);
msql>insert into books values('102938','Numerical Methods','Third',98.46);
msql>insert into authors values(1,'CS Liu');
mysql>insert into authors values(2,'N Deo');
mysql>insert into book_by_author values('123456',1);
mysql>insert into book_by_author values('123456',2);
mysql>commit;
Open the NetBeans IDE and create a Java Project
package javaapplication1;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try{
connection=DriverManager.getConnection
(DB_URL,DB_USER,DB_PASSWD);
statement=connection.createStatement();
resultSet=statement.executeQuery
("SELECT * FROM books");
while(resultSet.next()){
System.out.printf("%s\t%s\t%s\t%f\n",
resultSet.getString(1),
resultSet.getString(2),
resultSet.getString(3),
resultSet.getFloat(4));
}
}catch(SQLException ex){
}finally{
try {
resultSet.close();
statement.close();
connection.close();
} catch (SQLException ex) {
}
}
}
}
OUTPUT:
INFERENCE:
RESULT:
EX NO: 10
CASE STUDY USING REAL LIFE DATABASE APPLICATIONS
DATE:
AIM:-
To create a Mini project to implement the Operations of a Student Database using JAVA as
front-end and MYSQL as back-end.
DESIGN PLAN
1)Biodata:-
2)Attendence:-
3)Marks:-
3) Import the packages: Requires that you include the packages containing the JDBC classes
needed for database programming. Most often using import java.sql.* will suffice.
4) Register the JDBC driver:- Requires that you initialize a driver so you can open a
communication channel with the database.
Table Creation:-
Importjava.sql.*;
Importjavax.swing.JOptionPane;
Importjavax.swing.table.DefaultTableModel;
Button Coding:-
private void insertrecordActionPerformed(java.awt.event.ActionEventevt) {
try
{Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/sunil","root","rooty");
Statement stmt = conn.createStatement();
Class.forName("java.sql.Driver");
String nam = name.getText();
String roll = rollno.getText();
String regn = regno.getText();
String dbt = dob.getText();
stmt.executeUpdate("Insert into biodata values ('"+nam+"','"+roll+"',"+regn+" , '"+dbt+"')");
}
catch(Exception s){
JOptionPane.showMessageDialog(null, s.getMessage());
}
}
String n = rollno2.getText();
int r = Integer.parseInt(phy.getText());
int p= Integer.parseInt(chem.getText());
int d = Integer.parseInt(dbms.getText());
catch(Exception s){
JOptionPane.showMessageDialog(null, s.getMessage());
rollno2.setText("");
phy.setText("");
chem.setText("");
dbms.setText("");
try {
rs.next();
rollno2.setText(rs.getString(1));
phy.setText(Integer.toString(rs.getInt(2)));
chem.setText(Integer.toString(rs.getInt(3)));
dbms.setText(Integer.toString(rs.getInt(4)));
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e.getMessage());
SCREEN SHOTS:
INFERENCE:
RESULT :
CONTENT BEYOND SYLLABUS
INFERENCE
RESULT:
EX NO:14
REPORTS USING SQL
DATE:
AIM:
EXAMPLE 1
SQL> SET LINESIZE 80
SQL> TTITLE 'PIT STAFF'
SQL> select * from emp;
EXAMPLE 2
Employee Details
INFERENCE
RESULT:
EX NO:15
CALCULATE AREA OF CIRCLE USING PL/SQL PROGRAM
DATE:
AIM:
To write a pl/sql code block to calculate the area of a circle for a value of radius varying from
3 to 7. Store the radius and the corresponding values of calculated area in an empty table named
areas, consisting of two columns radius & area .
Procedure:
INFERENCE
RESULT