Lab ADT 1
Lab ADT 1
(Autonomous)
Komarapalayam-637303
LAB MANUAL
FOR
(Regulations-2023)
MS.M.DEEPASHRI AP/MCA
lOMoARcPSD|300 163 13
MONGODB-CRUD
1.a
OPERATIONS, INDEXING, SHARDING, DEPLOYMENT
EX.No:1 (a)
AIM:
To write NOSQL QUERIES to understand the concept of Open Source Database Management
System such as MongoDB.
ALGORITHM:
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;
switchedtodbmca
Insert:
> db.mca.studentInfo.insertOne({name:"Surya",age:23,town:"Salem"});
{
"acknowledged":true,
"insertedId":ObjectId("62f34f875705a8979214f6cd")
}
> db.mca.studentInfo.insertMany([{name:"Arya",age:23,town:"USA"},
... {name:"Saran",age:22,town:"Salem"},
... {name:"Ajith",age:21,town:"Namakkal"},
... {name:"Vijay",age:40,town:"Chennai"}
... ]);
{
"acknowledged":true,
"insertedIds" : [
lOMoARcPSD|300 163 13
ObjectId("62f34fde5705a8979214f6ce"),
ObjectId("62f34fde5705a8979214f6cf"),
ObjectId("62f34fde5705a8979214f6d0"),
ObjectId("62f34fde5705a8979214f6d1")
]
}
Update:
> db.mca.studentInfo.updateOne({name:"Vijay"},{$set:{age:22}});
Delete:
> db.mca.studentInfo.deleteOne({name:"Arya"})
> db.mca.studentInfo.remove({name:"Vijay"})
RESULT:
EX.No:1(b)
AIM:
To write NOSQL QUERIES to understand the concept of Open Source Database Management
System suchas CASSANDRA.
ALGORITHM:
cqlsh>CREATEKEYSPACEgctWITHreplication={'class':'SimpleStrategy',
'replication_factor': 3};
system_authsystem_distributedgctsystem_schemasystemsyst
em_tracescqlsh>usegct;
Create Table
cqlsh:gct>CREATETABLEVVT(IdintPRIMARYKEY,nametext,citytext,feesvarint);
Alter Table
cqlsh:gct>ALTER TABLE VVT ADD email text;
lOMoARcPSD|300 163 13
View Table
cqlsh:gct>select *fromvvt; id
Output
| city| email| fees| name
++++(0 rows)
Alter Table
cqlsh:gct>ALTER TABLE VVT DRO Pemail;
cqlsh:gct>select * from vvt;
Output
id|city|fees|name
+ + +
(0 rows)
Truncate Data
cqlsh:gct>TRUNCATEVVT;
cqlsh:gct>INSERTINTOVVT(Id,fees,name,city)VALUES(1,5000,'SuryaS','Nama
kkal'); cqlsh:gct>select * from vvt;
Output
id|city|fees|name
+_____+____+____+
1 | Namakkal | 5000 | SuryaS (1 rows)
Update Data
cqlsh:gct>UPDATEVVTSETfees=500,Name='SuryaS'WHEREid=1;
cqlsh:gct>select * from vvt;
select*fromvvt;
Output
id| city |fees| name
+ + +
1| Namakkal | 500 | Surya
2|Aathur|5000|Rahul
3|Salem|5000|Partha
DeleteData
cqlsh:gct>DELETE FROM VVTWHEREid=3;
cqlsh:gct>select * from vvt;
Output
id| city |fees| name
+ + +
1|Namakkal|500|SuryaS
2 |Aathur| 5000 | Rahul
(2 rows)
Drop Table
cqlsh:gct>describe column families vvt cqlsh: gct> DROP TABLE VVT;
cqlsh:gct>describe columnfamilies
<empty> cqlsh:gct>
RESULT:
EX.No:1(c)
HIVE:DATA TYPES, DATABASE OPERATIONS, PARTITIONING
DATE: HIVEQL
AIM:
To write NOSQL QUERIES to understand the concept of Open Source Database Management
System such as HIVE.
ALGORITHM:
Step 1: Start the Hadoop Cluster from sbin Folder (Run start-dfs, start-yarn).
Step 2: Start the derby node using the command (Start Network
Serverh0.0.0.0)
hive>showdatabases;
OK
Default
Timetaken:0.271seconds,Fetched:1row(s)
hive>create database demo;
hive>showdatabases;
OK
Timetaken:0.215seconds
hive>createadatabase ifnotexistsdemo; OK
Timetaken:0.107seconds
hive>createdatabasedemoWITHDBPROPERTIES('creator'='Natz','date'='2019-06-03'); OK
Timetaken:2.389seconds
hive>createtabledemo.employee(Idint,Namestring,Salaryfloat); OK
Timetaken:0.461seconds
hive>select*fromdemo.employee; OK
1 “SURYAS” 30000.0
2 “SUNDARS” 40000.0
3 “SURESHC” 50000.0
4 “MUNISH” 90000.0
lOMoARcPSD|300 163 13
hive>describedemo.employee
OK
id int
Name string
salary float
Timetaken:0.215seconds
hive>Altertableemployeerenametoemployee_data;
OK
Timetaken:6.06 seconds
hive>describeemployee_data;
OK
id int
Name string
salary float
Timetaken:0.275seconds
hive> show tables;
OK
Employee
Employee_data
Timetaken:0.098seconds,Fetched:2row(s)
hive>Altertableemployee_dataaddcolumns(ageint);
OK
id int
Namestring
salary float
age
Timetaken:0.275seconds
hive> show tables;
OK
employee
employee_data
Timetaken:0.098seconds,Fetched:2row(s)
hive>droptablenew_employee; OK
Timetaken:17.5seconds
hive>show tables;
OK
emp
employee
Time taken: 0.098 seconds
hive> drop database demo;
OK
Timetaken:2.354seconds
Static Partitioning
hive>usetest;
hive>create table student(id int,name string,age int,institutestring) partitionedby(coursestring);OK
Timetaken:3.054seconds
lOMoARcPSD|300 163 13
hive>describestudent;
OK
id int
name string
age int
institute course
course string
#PartitionInformation
#col_name data_type comment
Course string
Timetaken:1.054seconds,Fetched:10row(s)
RESULT:
EX.No:1(d)
AIM:
To write NOSQL QUERIES to understand the concept of Open Source Database Management
System such as Orient DB Graph.
ALGORITHM:
Step 1: Start the Server form the Orient DB in folder.
Step 3: Choose the Database and enter the username and password for the Orient DB Server.
Step 5: Create a Class, Node, Edges and Insert the fields Finally connect the graph display the output.
QUERIES
OUTPUT:
RESULT:
EX.No:2
AIM:
To write a Query for MySQL Database Creation, Table Creation and Some other Queries
Execution.
ALGORITHM:
Step1: Start the MYSQL Server.
.CREATETABLEmca.student_info(
id INT PRIMARY KEY,
nameVARCHAR(30),
age INT,
townVARCHAR(40)
);
Insert
INSERTINTOmca.student_infoVALUES
(1,"Surya",22,"Salem"),
(2,"Saran", 21, "Salem"),
(3,"Hari",22,"Namakkal"),
(4,"Vijay",21,"Salem"),
(5,"Ajith",22,"Erode"),
(6,"Vikram",21,"Chennai"),
(7,"Nantha",22,"Namakkal"),
(8,"Sathish",21,"Salem");
Update
UPDATEmca.student_infoSETtown="Salem"WHEREid=6;
lOMoARcPSD|300 163 13
Delete
DELETEFROMmca.student_infoWHEREid=5;
Read
SELECT*FROMmca.student_info;
OUTPUT:
RESULT:
EX.No:3
AIM:
To apply MYSQL replication technique in Distributed database.
ALGORITHM:
Step 1: Software to be need to run this Replication Java version1.8 and above MYSQL Server 8.05
WAMP Server
Step 2: Start the MYSQL Server and WAMP Server.
Step 3: Goto Browser in that type http://127.0.0.1/WampServerPagewillopen.
Step 5: Type User Name as „Root‟ and Password „‟ and hit enter
Step 6: Create a Database, Table in MYSQL using PHP MY ADMIN page.
Step 7:Need 2 MYSQL server, each running as a copy of PHP My Admin
Step 8: Your primary Moodle Database is referred to as the “master”, the replicated server will be
referred to as the“slave”
Step 9: Take an SQL dump of your master database and restore it on your slave database
Step 10: Now,on your master database login to PHP My Admin and click the Replication Tab
Replication Step2
4. Copy and paste the code this screen provides into the
very bottom of your MySQL configfile(my.ini on
Windows) AND add a line that says binlog_format=ROW (this fixes an error when running an
external DB enrollment sync with replication)
5. Restart the MySQL services on the master server, leave PHP My Admin Open though
6. Once the service has restarted ,click on “Go” on the PHP My Admin screen.
7. You will be redirected to the Replication screen which now looks like this
Replication Step3
8. Lastly, we need to create a replication user so click on the link that says “Add slave replication user”
9. Create a user and password, set the host to “Any” and click “Go”
10. On the privileges screen ensure the new user has both replication permissions checked and click “Go”
lOMoARcPSD|300 163 13
ReplicationStep4
11. Lastly, we need to create a replication user so click on the link that says “Add slave replication user”
12. Create a user and password, set the host to “Any” and click “Go”
13. On the privileges screen ensure the new user has both replication permissions checked and click “Go”
Replication Step 5
That’s all we need to do on the master server, now lets move over to the slave
14. From within PHP My Admin on the slave, click the replication tab
15. Then click the link to configure this server as slave replication
16. Copy the line of code that shows your new server id and paste this entire line into the
MySQL config file on your slave database server
17. Stop and start your My SQL service on the slave server
18. Now in PHP My Admin enter the user name of the replication user you createdinstep13
19. Enter the password and the host(the host name of the master server or its IP Address)
20. If your default port is not 3306 then change it, chance share it uses the default port
21. Click “Go”
lOMoARcPSD|300 163 13
Replication Step5
22. Itthentakesyoubacktothereplicationscreenandappearsasthoughit‟snot configured but it requiresa
refresh
23. So refresh the page and you will see it ‟s configured but not running
ReplicationStep6
ReplicationStep7
28. If everything is working then you will see a message against Slave_IO_Statethatreads “Waiting for
master tosend event”
RESULT:
Thus the above MYSQL replication program has been successfully executed.
lOMoARcPSD|300 163 13
EX.No:4
AIM:
ALGORITHM:
Step 6: In the output screen Select Form Edit or output will be displayed.
CREATEDATABASEspatial1;
CREATETABLEspatial1.restaurants( name
VARCHAR(20),
locationGEOMETRYNOTNULL,
SPATIAL INDEX(location)
);
INSERTINTOspatial1.restaurants
VALUES('Salem',ST_GeomFromText('POINT(11.65936578.157068)')),
('Erode',ST_GeomFromText('POINT(11.32467577.723072)')),
('Coimbatore',ST_GeomFromText('POINT(10.99323376.973483)')),
('Madurai',ST_GeomFromText('POINT(9.88389978.130947)')),
('Sivakasi',ST_GeomFromText('POINT(9.45187377.797697)')),
('Tirunelveli',ST_GeomFromText('POINT(8.72717377.703005)')),
('Rameswaram',ST_GeomFromText('POINT(9.26830379.243055)')),
('Thanjavur',ST_GeomFromText('POINT(10.78245179.137895)')),
('Puducherry',ST_GeomFromText('POINT(11.92936779.809884)'));
lOMoARcPSD|300 163 13
SELECTname,ST_AsText(location)FROMspatial1.restaurants
WHERE ST_Distance_Sphere(location, ST_GeomFromText('POINT(11.659365
78.157068)'))<=100*1000
ORDERBY name;
OUTPUT:
RESULT:
Thus the above program for spatial data storage and retrieval in MYSQL executed successfully.
lOMoARcPSD|300 163 13
EX.No:5
AIM:
ALGORITHM:
Step 3: Create Two Tables with the name of Customers and Orders.
CREATEDATABASEtemporal1;
CREATETABLEtemporal1.student_details(Student_IdINTAUTO_INCREMENT,
Contact_Details)VALUES('John','stark','2022-07-16','MCA',1234567890),('Arya','stark',
SELECT*FROMtemporal1.student_details;
lOMoARcPSD|300 163 13
OUTPUT:
RESULT:
Thus the above program Temporary data storage and retrieval as been executed successfully.
lOMoARcPSD|300 163 13
EX.No:6
OBJECT STORAGE AND RETRIEVAL IN MYSQL
DATE:
AIM:
To implement object storage and retrieval in MYSQL using Python programming language.
ALGORITHM:
Step 1: Start the SQL Server.
Step 7: Show the table after you make any changes in the table.
PROGRAM:
importmysql.connector
defconvertToBinaryData(filename):
"C:\\Users\\ABC\\Desktop\\flkimag\\static\\doc1.txt")
QUERY:
CREATEDATABASEpython_db;
CREATETABLEpython_db.python_employee(emp_idINTPRIMARYKEY,
name VARCHAR(50),
photo BLOB(200),
biodataBLOB(200)
);
OUTPUT:
lOMoARcPSD|300 163 13
RESULT:
Thus the above program for object creation and retrieval in MYSQL executed successfully using
python programming language
lOMoARcPSD|300 163 13
EX.No:7
AIM:
To Create a XML Databases in that create a XML Table and process the X Query FLOWR
Expressions
ALGORITHM:
Step 1: Create a XML Database in Notepad and save with an Extension filename.xml.
<?xmlversion="1.0"encoding="UTF-8"?>
<Test>
<Name>SuryaS</Name>
<Dept>ComputerScience</Dept>
<College>GCTCollege</College>
<City>Salem</City>
</Test>
Step 4: Create a XML Table in that use XQuery FLWOR expression filter the record.
Program1: (Book.xml)
<?xmlversion="1.0"encoding="UTF-8"?>
<books>
<bookcategory="ADT">
<titlelang="en">LearnADTin24Hours</title>
<author>Robert</author>
<college>GCT</college>
<year>2005</year>
<price>30.00</price>
</book>
lOMoARcPSD|300 163 13
<bookcategory="DOTNET">
<titlelang="en">Learn.Netin24hours</title>
<author>Peter</author>
<college>GCT</college>
<year>2011</year>
<price>40.50</price>
</book>
<bookcategory="XML">
<titlelang="en">LearnXQueryin24hours</title>
<author>Robert</author>
<author>Peter</author>
<college>GCT</college>
<year>2013</year>
<price>50.00</price>
</book>
<bookcategory="XML">
<titlelang="en">LearnXPathin24 hours</title>
<author>JayBan</author>
<college>GCT</college>
<year>2010</year>
<price>16.50</price>
</book>
</books>
Program2(books.xqy)
for$xindoc("books.xml")/books/boo
kwhere $x/price>30
returnstring($x/title)
OUTPUT:
Learn .Net in 24 hours
LearnXQueryin24hours
RESULT:
Thus the above program has XML FLOWR Query has been executed successfully.
lOMoARcPSD|300 163 13
EX.No:8
MOBILE DATABASE QUERY PROCESSING USING OPEN
DATE: SOURCE DB(MONGODB/MYSQL etc)
AIM:
To write a program for Mobile Database Query Processing using opensource DB using MongoDB
ALGORITHM:
Step 1: Open Eclipse and Import Java MESDK3.0.
Step 3: Open a New File JAVAMEMIDLET Project, Create a project Name and configure
below Emulator name.
Step 4: To establish a connection between JavaME to MongoDb Download the Jar file
mongodb-driver-3.2.2.jar and Import to Project Library
PROGRAM:
create_database.py
importsqlite3
conn = sqlite3.connect('database.db')
print ("Openeddatabasesuccessfully")
conn.execute('''CREATETABLEiotdata
1
(val TEXT,
key TEXT,
key1 TEXT);''')
print("Tablecreatedsuccessfully")
conn.close()
insert_data.py
importsqlite3
conn = sqlite3.connect('database.db')
print ("Openeddatabasesuccessfully")
conn.execute("INSERTINTOiotdata1(val,key,key1)VALUES(110,10,10)") conn.commit()
print("Recordscreatedsuccessfully")
conn.close()
lOMoARcPSD|300 163 13
api.py
fromflaskimport
* import sqlite3
app = Flask(name)
@app.route('/database1',methods=['GET']
deflogin():
a=request.args.get('mark1')
b=request.args.get('mark2')
c=request.args.get('mark3')
conn = sqlite3.connect('database.db')
print ("Openeddatabasesuccessfully")
conn.execute("insertintoiotdata1(val,key,key1)values(?,?,?)",(a,b,c))
conn.commit()
print("Recordscreatedsuccessfully")
conn.close()
return"OKRECORDED"
@app.route('/database2')
def login1():
return"OKRECORDED"
if name
=='main':
app.run(debug=True
)
OUTPUT:
lOMoARcPSD|300 163 13
RESULT:
Thus the above Mobile Database Query opensource DB using MongoDB program has been
successfully executed.
lOMoARcPSD|300 163 13