0% found this document useful (0 votes)
10 views31 pages

Lab ADT 1

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

Lab ADT 1

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

lOMoARcPSD|300 163 13

EXCEL ENGINEERING COLLEGE

(Autonomous)

Komarapalayam-637303

DEPARTMENT OF COMPUTER APPLICATIONS

LAB MANUAL

FOR

MASTER OF COMPUTER APPLICATIONS


I-SEMESTER

ADVANCE DATABASE TECHNOLOGY (23PMC106)

(Regulations-2023)

MS.M.DEEPASHRI AP/MCA
lOMoARcPSD|300 163 13

23PMC106-ADVANCE DATABASE TECHNOLOGY LABORATORY

S.NO EXPERIMENTS PAGE NO

MONGODB-CRUD
1.a
OPERATIONS, INDEXING, SHARDING, DEPLOYMENT

CASSANDRA: TABLE OPERATIONS, CRUD


1.b OPERATIONS, CQL TYPES.

1.c HIVE:DATA TYPES, DATABASE OPERATIONS,


PARTITIONING –HIVEQL

1.d ORIENTDB GRAPH DATABASE-ORIENTDB FEATURES

2 MYSQL DATABASE CREATION, TABLE CREATION, QUERY

3 MYSQL REPLICATION-DISTRIBUTED DATABASES

4 SPATIAL DATA STORAGE AND RETRIEVAL IN MYSQL

TEMPORAL DATA STORAGE AND RETRIEVAL INMYSQL


5

6 OBJECT STORAGE AND RETRIEVAL IN MYSQL

XML DATABASES, XML TABLE CREATION, XQUERYFLOWR


7 EXPRESSION

MOBILE DATABASE QUERY PROCESSING USING OPEN


8 SOURCE DB
lOMoARcPSD|300 163 13

EX.No:1 (a)

DATE: MONGODB-CRUD OPERATIONS,INDEXING,SHARDING,DEPLOYMENT

AIM:
To write NOSQL QUERIES to understand the concept of Open Source Database Management
System such as MongoDB.
ALGORITHM:

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)

QUERIES WITH EXECUTION:

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:

Thus the above MongoDB Queries has been executed successfully.


lOMoARcPSD|300 163 13

EX.No:1(b)

DATE: CASSANDRA: TABLE OPERATIONS, CRUD OPERATIONS, CQL TYPES.

AIM:
To write NOSQL QUERIES to understand the concept of Open Source Database Management
System suchas CASSANDRA.

ALGORITHM:

Step 1: Start the CASSANDRA Server (Cassandra) using CMD.


Step 2: Start the Client (CQLSH.py) using CMD.
Step 3: Perform the Cassandra Table Operation, Curd Operation and CQL
Types. CassandraTable Operations:

1. Create Key Space in Cassandra. CREATEKEYSPACE<identifier>WITH<properties>


2. To Create Cassandra Table, Using Create Command.
3. To Change the structure of the table, Using Alter Command.
4. To delete the existing table in Cassandra, Using Truncate Command.
5. To Insert the values in CQL, use insert command
6. The SELECT command issued to read data from Cassandra table
7. The UPDATE command issued to update the existing data in a Cassandra.
8. The DELETE command issued to delete data from Cassandra table

Step 4 : Close the command prompt


Step 5 : Stop the Server.

QUERIES WITH EXECUTION:

Create Key Space:

cqlsh>CREATEKEYSPACEgctWITHreplication={'class':'SimpleStrategy',
'replication_factor': 3};

cqlsh>describe key spaces;//Display the Created Key Spaces

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:

Thus the above Cassandra Queries has been executed successfully.


lOMoARcPSD|300 163 13

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)

Step 3: Then Start the Hive.(Hive command)


Step 4: Hive datatype share 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 that showdatabase;
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.

QUERIES WITH EXECUTION:

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:

Thus the above Hive Queries has been executed successfully.


lOMoARcPSD|300 163 13

EX.No:1(d)

DATE: ORIENTDB GRAPH DATABASE-ORIENTDB FEATURES

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 2: Use the respectiveurlhttp://192.168.43.111:2480/studio/index.html to login to Orient DB browser.

Step 3: Choose the Database and enter the username and password for the Orient DB Server.

Step 4: In theMenu choose the Graph Tab.

Step 5: Create a Class, Node, Edges and Insert the fields Finally connect the graph display the output.

Step 6:Logout from the Browser.

Step 7: Stop the Server.

QUERIES

Create class gct extend sv


create vertex gct set name='ahmed',class='I_MCA'
create vertex gct set name='bala',class='I_MCA'
create vertex gct set name='partha',class='I_MCA'
createvertexgctsetname='praveen',class='I_MCA'
create vertex gct set name='tamil',class='I_MCA'
create vertex gct set name='ragul',class='I_MCA'
create edge from #43:0 to #44:0
createedgefrom#43:0to#45:0
createedgefrom#46:0to#46:0
createedgefrom#43:1to#44:0
createedgefrom#44:1to #45:0
select *fromgct;
lOMoARcPSD|300 163 13

OUTPUT:

RESULT:

Thus the above OrientDB Queries has been executed successfully.


lOMoARcPSD|300 163 13

EX.No:2

DATE: MYSQL DATABASE CREATION, TABLE CREATION, QUERY

AIM:
To write a Query for MySQL Database Creation, Table Creation and Some other Queries
Execution.

ALGORITHM:
Step1: Start the MYSQL Server.

Step 2: Open MySQL Command Line Client

Step 3: Write and Execute Queries for Database Creation

Step 4: Write and Execute Queries for Table Creation


Step 5: Verify with Show Command to Check whether the Database and Table Created.
Step 6: Do some other Queries Execution like insert, update, delete a record.
Step 7: Close MySQL Command Line Client
Step 8: Stop the MYSQL Server.

QUERIES WITH EXECUTION:

CREATE DATABASE mca;

.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:

Thus the above MYSQL Queries has been executed successfully.


lOMoARcPSD|300 163 13

EX.No:3

DATE: MYSQL REPLICATION-DISTRIBUTED DATABASES

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 4: In the bottom select tools PHP My Admin it will redirect to


http://127.0.0.1/phpmyadmin/

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

Configure the Master

MySQL Replication Step1

1. Now click the link to configure this as the master server


lOMoARcPSD|300 163 13

2. Select “Ignore all databases, replicate:”


3. Select your Moodle database from the available list(see below)

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

24. Click “Control slave” then click “Full Start”


25. PHP My Admin now sits there with a Loading window, after a while this will time out, if this
happens or indeed after 5minutes nothing happens then reload the replication page again(refres it).
26. When the page reloads(either automatically or manually forced by you, you will see no error
warning sand a message that says “Server is configured as slave”
27. Now to check it ‟working, click on the link that says “See slave status table”
lOMoARcPSD|300 163 13

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

DATE: SPATIAL DATA STORAGE AND RETRIEVAL IN MYSQL

AIM:

To implement spatial data storage and retrieval in MYSQL.

ALGORITHM:

Step1: Start the MYSQLServer.

Step 2: Create a Database.

Step 3: Create a table with spatial datatype.

Step 4: Insert the spatial values in the table.

Step 5: Display the output using the select command

Step 6: In the output screen Select Form Edit or output will be displayed.

QUERIES WITH EXECUTION:

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

DATE: TEMPORAL DATA STORAGE AND RETRIEVAL IN MYSQL

AIM:

To Create a Temporal data storage and retrieve that data in mysql.

ALGORITHM:

Step1: Start the MYSQL Server.

Step 2: Create a Database.

Step 3: Create Two Tables with the name of Customers and Orders.

Step 4: Insert Some record in that tables.

Step 5: Create a Temporary Table by using the object we can create it

Step 6:Show the temporary table.

QUERIES WITH EXECUTION:

CREATEDATABASEtemporal1;

CREATETABLEtemporal1.student_details(Student_IdINTAUTO_INCREMENT,

First_name VARCHAR (100) NOT NULL,Last_name VARCHAR (100) NOT NULL,

Date_Of_Birth DATE NOT NULL, Class VARCHAR (10) NOT NULL,Contact_Details

BIGINT NOT NULL,PRIMARY KEY(Student_Id ));

INSERTINTOtemporal1.student_details(First_name, Last_name, Date_Of_Birth,Class,

Contact_Details)VALUES('John','stark','2022-07-16','MCA',1234567890),('Arya','stark',

'2003-06-10', 'BE' , 1214657890);

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 2: Create a Database “gct” and Table “mca” in MYSQL

Step 3: In Python import mysql.connect or to connect MYSQL with Python

Step 4: Create an object in python and insert that object in table

Step 5: Execute the SQL query.

Step 6: Fetch records from the result.

Step 7: Show the table after you make any changes in the table.

PROGRAM:

importmysql.connector

defconvertToBinaryData(filename):

#Convert digital data to binary format with open(filename,'rb')asfile:


binaryData=file.read()
returnbinaryData
definsertBLOB(emp_id,name,photo,biodataFile):
print("InsertingBLOBintopython_employee table")
try:
connection = mysql.connector.connect(host='localhost', database='python_db', user='root',password='')
cursor = connection.cursor()
blob_query="""INSERTINTOpython_employee(emp_id,name,photo,biodata)VALUES
(%s,%s,%s,%s)"""
empPicture = convert To Binary Data(photo)file = convert To Binary
Data(bio data File)
#Convertdataintotuple format
insert_blob_tuple=(emp_id,name,empPicture,file)
lOMoARcPSD|300 163 13

result = cursor.execute(sql_insert_blob_query, insert_blob_tuple)


connection.commit() print("Image and file inserted successfully as a BLOB into
python_employee table",result)
except mysql.connector. Error as error:
print("Failed inserting BLOB data into MySQL table{}".format(error))
finally:
ifconnection.is_connected():
cursor.close()
connection.close()
print("MySQL connection is closed")
insertBLOB(3, "myimage", "C:\\Users\\ABC\\Desktop\\flkimag\\static\\images.jpg",

"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

DATE: XML DATABASES, XML TABLE CREATION, XQUERY FLOWR


EXPRESSION

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.

Step 2:Open Notepad.

<?xmlversion="1.0"encoding="UTF-8"?>
<Test>
<Name>SuryaS</Name>
<Dept>ComputerScience</Dept>
<College>GCTCollege</College>
<City>Salem</City>
</Test>

Step 3: Create multiple records in a table.

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 2: In Device Management Manually in stall the Java MESDK Files.

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

Step 5: Import the Necessary header files.


Step 6: use MONGOCLIENT to establish connection between MONGODBSERVERTOJAVAME.
Step 7:create Collection in mongodb console.
Step 8: By using find() display all the records in collections.

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

You might also like