0% found this document useful (0 votes)
15 views

DB 510

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

DB 510

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

EXPERIMENT NO.

: 5
Name : Nitishkumar

Roll No : 37

1.TRIGGER:

-To implement trigger firstly we create table

mysql> create table Account (Anum int(10), amount decimal(10,2);

mysql> desc account;

+ + + + + + +

| Field | Type | Null | Key | Default | Extra |

+ + + + + + +

| Anum | int | YES | | NULL | |

| amount | decimal(10,2) | YES | | NULL | |

+ + + + + + +

mysql> create trigger holder before insert on Account for each row set @sum = @sum +new.amount;

mysql> set @sum = 0;

mysql> insert into account values(137,14.98),(141,1937.50),(97,-100.00);

mysql> select @sum as 'Total amount inserted';

+ +

| Total amount inserted |

+ +

| 1852.48 |

+ +

mysql> desc account;

+ + + + + + +

| Field | Type | Null | Key | Default | Extra |

+ + + + + + +

| Anum | int | YES | | NULL | |

| amount | decimal(10,2) | YES | | NULL | |

+ + + + + + +

2.INDEX:-

mysql> select* from students;

+ + + + +

| id | fname | lname | department |

+ + + + +

| 1 | tanmay | mhetras | cse |

| 2 | Rohit | khilari | mech |

| 3 | prathmesh | surwase | cse |

| 4 | sai | kurapati | mech |

| 5 | vedant | joshi | cse |

| 6 | nikhil | neel | ee |

| 7 | amey | kulkarni | entc |

1
+ + + + +

mysql> create index department on students(department);

Mysql> show indexes from students;

Output:-

SQL Date and Time Data Types: -

1. Date

2. Time

3. Timestamp

mysql> desc information;

+ + + + + + +

| Field | Type | Null | Key | Default | Extra |

+ + + + + + +

| id | int | NO | PRI | NULL | auto_increment |

| date_joining | date | YES | | NULL | |

| joining_time | time | YES | | NULL | |

| bothdatetime | timestamp | YES | | NULL | |

+ + + + + + +

mysql> insert into inforamation(date_joining,joining_time, bothdatetime) values('2002-07-22','08:25:45','2002-07-22 08:25:45');

mysql> select* from inforamation;

+ + + + +

| id | date_joining | joining_time | bothdatetime |

+ + + + +

| 1 | 2002-07-22 | 08:25:45 | 2002-07-22 08:25:45 |

+ + + + +

mysql> insert into inforamation(date_joining,joining_time, bothdatetime) values(curdate(),curtime(),now());

mysql> select* from inforamation;

+ + + + +

| id | date_joining | joining_time | bothdatetime |

+ + + + +

| 1 | 2002-07-22 | 08:25:45 | 2002-07-22 08:25:45 |

| 2 | 2022-11-08 | 11:49:44 | 2022-11-08 11:49:44 |

2
EXPERIMENT NO.: 7
Name : Nitishkumar

Roll No : 37

 Database Connectivity using JDBC

Java program for database connectivity :-

import java.sql.*;
public class MySqlCon {
public static void main(String args[]){
try{ Class.forName("com.mysql.cj.jdbc.Drive
r"); Connection
con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/student","root","Nikhil@12");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from student");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
con.close();
}catch(Exception e){ System.out.println(e);}
}
}

Steps for Connectivity are as follows :

1. Search for MySql Java Connector in Chrome.


Click on the first link https://dev.mysql.com/downloads/connector/j/

2. Select Operating System as Platform Independent and Download the second file.

3. Select specified folder for the file


3
4. Download Eclipse from https://www.eclipse.org/downloads/
Click on Download and install Eclipse.

5. Check the Downloaded files

6. Extract the mysql-connector jar file to specified folder.

4
7. Open Eclipse, Create class MySqlCon and write the database connectivity
Java program

8. Right cilck on Project folder, Select Build path and click on Configure Build path

5
9. Select Java Build path click on libraries and Select Module Path
Click on Add External JARs

10. Select the jar file

11. Click on Apply and then Apply and Close

6
12. The jar file will be added to the Refrence libraries of Package

13. Run the Program to see the Output…


\

7
EXPERIMENT NO : 8
Name : Nitishkumar
Roll No : 37

1. Insert
package mysqlcon;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;

class connect{

public static void main(String args[]){

try{

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

Connection con=DriverManager.getConnection(

"jdbc:mysql://localhost:3306/rohit","root","student");

Statement stmt=con.createStatement();

int result=stmt.executeUpdate("insert into


student(Roll_No,Name,age,address,Marks)values('5','abc','19','solapur','80')");

ResultSet rs=stmt.executeQuery("select * from student");

while(rs.next())

System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));

con.close();

}catch(Exception e){ System.out.println(e);}

Output:

1 Rohit 21
2 Amey 24
3 Laxmiputra 67
4 Nikhil 38
5. abc 19

8
01. Update:
package mysqlcon;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;

class connect{

public static void main(String args[]){

try{

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

Connection con=DriverManager.getConnection(

"jdbc:mysql://localhost:3306/rohit","root","student");

Statement stmt=con.createStatement();

int result=stmt.executeUpdate("update student set Name='amey' where Roll_No='2'");

ResultSet rs=stmt.executeQuery("select * from student");

while(rs.next())

System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));

con.close();

}catch(Exception e){ System.out.println(e);}

Output:

1 Rohit 21
2 aney 24
3 Laxmiputra 67
4 Nikhil 38
5. abc 19

9
03.Delete:
package mysqlcon;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
class connect{
public static void main(String args[]){
try{ Class.forName("com.mysql.jdbc.Driver")
; Connection
con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/rohit","root","student");
Statement stmt=con.createStatement();
int result=stmt.executeUpdate("delete from student where Roll_No='5'");
ResultSet rs=stmt.executeQuery("select * from student");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
con.close();
}catch(Exception e){ System.out.println(e);}
}
}

Output:

1 Rohit 21
2 Amey 24
3 Laxmiputra 67
4 Nikhil 38

10
EXPERIMENT NO: 9
Name : Nitishkumar
Roll No : 37

B+ tree (implementation in python)


self.keys = [[key]]
import math class BplusTree:
class Node: def init (self, order):
def init (self, order): self.root = Node(order)
self.order = order self.root.check_leaf = True
self.values = []

self.keys = []

self.nextKey = None def insert(self, value, key):


self.parent = None value = str(value)
self.check_leaf = False old_node = self.search(value)

old_node.insert_at_leaf(old_node, value, key)

def insert_at_leaf(self, leaf, value, key): if (len(old_node.values) == old_node.order):


if (self.values): node1 = Node(old_node.order)
temp1 = self.values node1.check_leaf = True
for i in range(len(temp1)): node1.parent = old_node.parent
if (value == temp1[i]): mid = int(math.ceil(old_node.order / 2)) - 1
self.keys[i].append(key) node1.values = old_node.values[mid + 1:]
break node1.keys = old_node.keys[mid + 1:]
elif (value < temp1[i]): node1.nextKey = old_node.nextKey
self.values = self.values[:i] + [value] + old_node.values = old_node.values[:mid +
self.values[i:] 1]
self.keys = self.keys[:i] + [[key]] + old_node.keys = old_node.keys[:mid +
self.keys[i:]
1] old_node.nextKey = node1
break
self.insert_in_parent(old_node,
elif (i + 1 == len(temp1)): node1.values[0], node1)
self.values.append(value)
self.keys.append([key])

break def search(self, value):


else: current_node = self.root
self.values = [value]

11
while(current_node.check_leaf == False): parentNode = n.parent
temp2 = current_node.values temp3 = parentNode.keys
for i in range(len(temp2)): for i in range(len(temp3)):
if (value == temp2[i]): if (temp3[i] == n):
current_node = current_node.keys[i + parentNode.values =
1] parentNode.values[:i] + \
break [value] + parentNode.values[i:]
elif (value < temp2[i]): parentNode.keys = parentNode.keys[:i

current_node = 1] + [ndash] +
current_node.keys[i] parentNode.keys[i +
1:]
break
ndash.parent = rootNode
elif (i + 1 == len(current_node.values)):
return
current_node = current_node.keys[i +
1]

break

return current_node

def find(self, value, key):

l = self.search(value)

for i, item in enumerate(l.values):

if item == value:

if key in l.keys[i]:

return True

else:

return False

return False

def insert_in_parent(self, n, value, ndash):

if (self.root == n):

rootNode = Node(n.order)

rootNode.values = [value]

rootNode.keys = [n, ndash]

self.root = rootNode

n.parent = rootNode

12
if j.parent = parentNode
(len(parentNode.k
eys) > for j in parentdash.keys:
parentNode.order j.parent = parentdash
):
self.insert_in_parent(parentNode,
parentdash = value_, parentdash)
Node(parentNode.or

der)

parentdash.parent = def delete(self, value, key):


parentNode.parent
node_ = self.search(value)
mid = int(math.ceil(parentNode.order
/
2)) - 1

par
entdash.value
s=
parentNode.v
alues[mid +
1:]

p
arentdash.k
eys =
parentNode.
keys[mid +
1:]

value_ =

parentNode.val

ues[mid] if (mid

== 0):

par
entNode.values =
parentNode.valu
es[:mid + 1]

else:

parentNode.values
= parentNode.values[:mid]

p
arentNode.k
eys =
parentNode.
keys[:mid +
1]

for j in

parent

Node.k

eys:

13
temp = 0 if self.root == node_ and len(node_.keys) == 1:
for i, item in enumerate(node_.values): self.root = node_.keys[0]
if item == value: node_.keys[0].parent = None
temp = 1 del node_

return
if key in node_.keys[i]: elif (len(node_.keys) <
int(math.ceil(node_.order / 2)) and
if len(node_.keys[i]) > 1:
node_.check_leaf == False) or (len(node_.values) <
int(math.ceil((node_.order - 1) / 2)) and
node_.keys[i].pop(node_.keys[i].index(key)) node_.check_leaf == True):

elif node_ == self.root:

node_.values.pop(i) is_predecessor = 0

node_.keys.pop(i) parentNode = node_.parent

else: PrevNode = -1

NextNode = -1
node_.keys[i].pop(node_.keys[i].index(key))
PrevK = -1
del node_.keys[i]
PostK = -1

for i, item in enumerate(parentNode.keys):


node_.values.pop(node_.values.index(value))

self.deleteEntry(node_, value, key)


if item == node_:
else:
if i > 0:
print("Value not in
PrevNode = parentNode.keys[i - 1]
Key") return
PrevK = parentNode.values[i - 1]
if temp == 0:

print("Value not in Tree")


if i < len(parentNode.keys) - 1:
return
NextNode = parentNode.keys[i + 1]

PostK = parentNode.values[i]

def deleteEntry(self, node_, value, key):


if PrevNode == -1:

ndash = NextNode
if not node_.check_leaf:
value_ = PostK
for i, item in enumerate(node_.keys):
elif NextNode == -1:
if item == key:
is_predecessor = 1
node_.keys.pop(i)
ndash = PrevNode
break
value_ = PrevK
for i, item in enumerate(node_.values):
else:
if item == value:
if len(node_.values) +
node_.valbreak
len(NextNode.values) < node_.order:
14
ndash = NextNode break

value_ = PostK else:

else: ndashpm = ndash.keys.pop(-1)


is_predecessor = 1 ndashkm = ndash.values.pop(-1)

ndash = PrevNode node_.keys = [ndashpm] +


node_.keys
value_ = PrevK
node_.values = [ndashkm] +
node_.values
if len(node_.values) + len(ndash.values) < parentNode = node_.parent
node_.order:
for i, item in enumerate(p.values):
if is_predecessor == 0:
if item == value_:
node_, ndash = ndash, node_
parentNode.values[i] = ndashkm
ndash.keys += node_.keys
break
if not node_.check_leaf:

ndash.values.append(value_) else:

else: if not node_.check_leaf:

ndash.nextKey = ndashp0 = ndash.keys.pop(0)

node_.nextKey ndash.values += ndashk0 = ndash.values.pop(0)

node_.values node_.keys = node_.keys + [ndashp0]

node_.values = node_.values +
if not
[value_]
ndash.check_leaf: for j
parentNode = node_.parent
in ndash.keys: j.parent
for i, item in
= ndash
enumerate(parentNode.values):

self.deleteEntry(node_.parent, value_, if item == value_:


node_) parentNode.values[i] = ndashk0
del node_ break
else: else:
if is_predecessor == 1:
ndashp0 = ndash.keys.pop(0)
if not node_.check_leaf: ndashk0 = ndash.values.pop(0)
ndashpm = ndash.keys.pop(-1) node_.keys = node_.keys + [ndashp0]
ndashkm_1 = ndash.values.pop(-1) node_.values = node_.values +
node_.keys = [ndashpm] + [ndashk0]
node_.keys parentNode = node_.parent
node_.values = [value_] + for i, item in
node_.values
if item == value_: p.values[i] = ndashkm_1
parentNode = node_.parent

for i, item in
enumerate(parentNode.values):

15
enumerate(parentNode.values):

if item ==

value_:

parent

Node.v

alues[i]

=
ndash.values[0]

break

16
if not ndash.check_leaf:

for j in ndash.keys: flag = 1

j.parent = ndash

if not

node_.check_leaf: for j

in node_.keys: j.parent

= node_

if not

parentNode.check_leaf: for j

in parentNode.keys: j.parent

= parentNode

def printTree(tree):

lst = [tree.root]

level = [0]

leaf = None

flag = 0

lev_leaf = 0

node1 = Node(str(level[0]) +
str(tree.root.values))

while (len(lst) != 0):

x = lst.pop(0)

lev = level.pop(0)

if (x.check_leaf == False):

for i, item in enumerate(x.keys):

print(item.values)

else:

for i, item in enumerate(x.keys):

print(item.values)

if (flag == 0):

lev_leaf = lev

leaf = x

17
record_len = 3 5', '10')): print("Found")

bplustr else:

ee = print("Not found")

BplusT

ree(rec

ord_le

n) Output

bplustr

ee.inse

rt('5', ['15', '25']

'33') ['35', '45']

bplustree.insert('15', '21') ['5']

bplustree.insert('25', '31') Found

bplustree.insert('35', '41')

bplustree.insert('45', '10')

printTree(bplustree)

if(

'

18
EXPERIMENT NO :- 10

Name : Nitishkumar

Roll No. : 37

Dynamic Hashing (implementation in python) :

def display_hash(hashTable):

for i in range(len(hashTable)):
print(i, end = " ")

for j in hashTable[i]:
print("-->", end = " ")
print(j, end = " ")

print()

HashTable = [[] for _ in range(5)]

def Hashing(keyvalue):
return keyvalue % len(HashTable)

def insert(Hashtable, keyvalue, value):

hash_key = Hashing(keyvalue)
Hashtable[hash_key].append(value)

insert(HashTable, 12, 'PUNE')


insert(HashTable, 15, 'SOLAPUR')
insert(HashTable, 19, 'MUMBAI')
insert(HashTable, 7, 'NAGPUR')
insert(HashTable, 47, 'RATNAGIRI')
insert(HashTable, 26, 'KOLHAPUR')

19
display_hash (HashTable)

20
OUTPUT
Bucket List ................

0 --> SOLAPUR

1 --> KOLHAPUR

2 --> PUNE --> NAGPUR --> RATNAGIRI

4 --> MUMBAI

21

You might also like