Dbms Assignment 4
Dbms Assignment 4
B-4
Assignment No. B4
Title: Write a program to implement MogoDB database connectivity with Java Implement
Database navigation operations (add, delete, edit etc. ) using
ODBC/JDBC.
import java.net.UnknownHostException;
import java.util.Scanner; import
com.mongodb.*;
public class DatabaseConnectivity
{private static void choice_input(){
1.insertdatainto database\n2.updatedatabase
documents\n3.delete database documents\n4.show database
collections\n5.Exit");
key = scanner.next();
System.out.println("Enter searched value: ");
value = scanner.next(); searchObj .put(key,
value);
BasicDBObject newObj = new BasicDBObject(); System.out.println("Enter
new key: ");
key = scanner.next();
System.out.println("Enter new value: ");
value = scanner.next();
newObj.put(key,value);
collection.update(searchObj, newObj);
break; case 3:
System.out.println("Enter removable key: "); key =
scanner.next();
System.out.println("Enter removable value: ");
value = scanner.next();
BasicDBObject removableObj = new
BasicDBObject(); removableObj.put(key,value);
collection.remove(removableObj); break; case 4:
DBCursor cursorDoc = collection.find(); while
(cursorDoc.hasNext()) {
System.out.println(cursorDoc.next()); break;
case 5:
System.exit(0)
;
break;)
while(choice!
= 6);
Output