PL-1 Asssignments

PL-1 Asssignments

===============================

Practical: A1 Two tier client server mysql

===============================


//On server Pc...


gescoe@gescoe:~$ mysql -u root -p                                          //To open mysql
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 36
Server version: 5.5.38-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> grant all on *.* to 'userall'@'%' identified by '';                  //To give access to all(%) clients through server
Query OK, 0 rows affected (0.00 sec)


mysql> select user, password ,host from mysql.user;                         //To display whether created user
+------------------+-------------------------------------------+---------------+
| user             | password                                  | host          |
+------------------+-------------------------------------------+---------------+
| root             | *869CD83D2CDA53A290DB1C0D0CBE77BA7ABE798C | localhost     |
| root             | *869CD83D2CDA53A290DB1C0D0CBE77BA7ABE798C | gescoe        |
| root             | *869CD83D2CDA53A290DB1C0D0CBE77BA7ABE798C | 127.0.0.1     |
| root             | *869CD83D2CDA53A290DB1C0D0CBE77BA7ABE798C | ::1           |
| debian-sys-maint | *515CCE4618BF63AD954BA957AF3C5125B117EE6D | localhost     |
| user02           |                                           | 192.168.2.222 |
| userall          |                                           | %             |
+------------------+-------------------------------------------+---------------+
7 rows in set (0.00 sec)



mysql> create database TE4;                            //create new database

Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| DMSA               |
| T4                 |
| TE4                |
| mysql              |
| performance_schema |
+--------------------+
6 rows in set (0.00 sec)


mysql> use TE4;                                    //select database for creating table
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed



mysql> create table Student (Rollno int,Name varchar(20),Branch varchar(20),Percent float,primary key(Rollno));    //create table
Query OK, 0 rows affected (0.08 sec)

mysql> desc Student;
+---------+-------------+------+-----+---------+-------+
| Field   | Type        | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| Rollno  | int(11)     | NO   | PRI | 0       |       |
| Name    | varchar(20) | YES  |     | NULL    |       |
| Branch  | varchar(20) | YES  |     | NULL    |       |
| Percent | float       | YES  |     | NULL    |       |
+---------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)


mysql> show tables;                                //Display created table
+---------------+
| Tables_in_TE4 |
+---------------+
| PLI           |
| Student       |
| stud          |
+---------------+
3 rows in set (0.00 sec)


mysql> select * from Student;                                                 //display table data inserted by client pc
+--------+--------+----------+---------+
| Rollno | Name   | Branch   | Percent |
+--------+--------+----------+---------+
|      1 | NAVIN  | Computer |      75 |
|      2 | ANUSHA | Computer |      75 |
|      3 | VEENA  | Computer |      60 |
|      4 | RAVI   | Computer |      60 |
+--------+--------+----------+---------+
4 rows in set (0.00 sec)



mysql> select * from Student;                            //display table data entry updated by client pc
+--------+--------+----------+---------+
| Rollno | Name   | Branch   | Percent |
+--------+--------+----------+---------+
|      1 | NAVIN  | Computer |      75 |
|      2 | ANUSHA | IT       |      75 |
|      3 | VEENA  | Computer |      60 |
|      4 | RAVI   | Computer |      60 |
+--------+--------+----------+---------+
4 rows in set (0.00 sec)



mysql> select * from Student;                            //display table data entry deleted by client pc
+--------+--------+----------+---------+
| Rollno | Name   | Branch   | Percent |
+--------+--------+----------+---------+
|      1 | NAVIN  | Computer |      75 |
|      2 | ANUSHA | IT       |      75 |
|      4 | RAVI   | Computer |      60 |
+--------+--------+----------+---------+
3 rows in set (0.00 sec)



------------------------------



//On client pc

gescoe@gescoe:~$ mysql -u userall -h 192.168.2.223 -p                 // to connect server(ip) pc
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 40
Server version: 5.5.38-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.




mysql> show databases;                                    //AVAILABLE DATABASES
+--------------------+
| Database           |
+--------------------+
| information_schema |
| DMSA               |
| T4                 |
| TE4                |
| mysql              |
| performance_schema |
+--------------------+
6 rows in set (0.00 sec)



mysql> insert into Student (Rollno,Name,Branch,Percent) values (1,'NAVIN','Computer',75);            //INSERTING DATA
Query OK, 1 row affected (0.03 sec)

mysql> insert into Student (Rollno,Name,Branch,Percent) values (2,'ANUSHA','Computer',75);
Query OK, 1 row affected (0.03 sec)

mysql> insert into Student (Rollno,Name,Branch,Percent) values (3,'VEENA','Computer',60);
Query OK, 1 row affected (0.03 sec)

mysql> insert into Student (Rollno,Name,Branch,Percent) values (4,'RAVI','Computer',60);
Query OK, 1 row affected (0.08 sec)






mysql> update Student set Branch='IT' where Rollno=2;                                //UPDATE DATA
Query OK, 1 row affected (0.19 sec)
Rows matched: 1  Changed: 1  Warnings: 0




mysql> delete from Student where Rollno=3;                                    // DELETE DATA
Query OK, 1 row affected (0.03 sec)




===============================

Practical: A2 Three tier Mysql

===============================



 
//PROGRAM:-

import java.lang.*;
import java.sql.*;
import java.io.*;

public class Javasql1
{
public static void main(String[] args)
{
int ch;
String q;
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String url = "jdbc:mysql://localhost/";
String driver = "com.mysql.jdbc.Driver";
String dbName = "studinfo";
String userName = "root";
String password="gescoe";

try{

Connection conn = DriverManager.getConnection(url+dbName,userName,password);
Statement st = conn.createStatement();
ResultSet res;
do
{

System.out.println("\n---------MENU---------");
System.out.println("\n1.Create Tables");
System.out.println("\n2.Insert Records");
System.out.println("\n3.Joins");
System.out.println("\n4.Exit");
System.out.println("\n\nEnter your choice:");
ch=Integer.parseInt(input.readLine());

switch(ch)
{
case 1:
System.out.println("\nCreating two table:student and marks");

q="CREATE TABLE students(Roll_No int,Name VARCHAR(10),Department varchar(10));";
st.executeUpdate(q);

q="CREATE TABLE marks(Roll_No int,Name varchar(10),Internal_Marks int,External_Marks int);";
st.executeUpdate(q);
System.out.println("\n'students' and 'marks'table Successfully created\n");
break;

case 2:
q = "INSERT INTO students VALUES(101,'Shubha','IT');";
st.executeUpdate(q);
q = "INSERT INTO students VALUES(112,'Rohini','Civil');";
st.executeUpdate(q);
q = "INSERT INTO students VALUES(103,'Nishi','Computer');";
st.executeUpdate(q);
q = "INSERT INTO students VALUES(174, 'Anushka','Computer');";
st.executeUpdate(q);
q = "INSERT INTO students VALUES(115,'Anuja','IT');";
st.executeUpdate(q);

q = "INSERT INTO marks VALUES(103,'Nishi',38,43);";
st.executeUpdate(q);
q = "INSERT INTO marks VALUES(133,'Raj',35,39);";
st.executeUpdate(q);
q = "INSERT INTO marks VALUES(174,'Anushka',43,45);";
st.executeUpdate(q);
q = "INSERT INTO marks VALUES(111,'Sham',40,41);";
st.executeUpdate(q);
q = "INSERT INTO marks VALUES(115,'Anuja',30,34);";
st.executeUpdate(q);

System.out.println("\nInserted records into the tables 'students' and 'marks' successfully...\n");
break;

case 3:
do{
System.out.println("\n\n-------Joins-------\n");
System.out.println("\n1.INNER JOIN");
System.out.println("\n2.LEFT OUTER JOIN");
System.out.println("\n3.RIGHT OUTER JOIN");
System.out.println("\n4.FULL OUTER JOIN");
System.out.println("\n5.Exit");
System.out.println("\n\nEnter your choice:");
ch=Integer.parseInt(input.readLine());
switch(ch)
{
case 1: q="SELECT students.Roll_No,students.Name, students.Department FROM students INNER JOIN marks ON students.Roll_No=marks.Roll_No;";
res=st.executeQuery(q);
System.out.println("\n\t-------------------------------------
---------------------------------");
System.out.println("\n\t\t\t\tRECORDS");
System.out.println("\n\t------------------------------------
-------------------------------\n");
while (res.next())
{
int rollno = res.getInt("Roll_No");
String name = res.getString("Name");
String department = res.getString("Department");

System.out.println("\n\tRoll No:"+rollno+"\t Name:"+name+"\tDepartment:"+department+"\n");
}
System.out.println("\n\t----------------------------------
-----------------------------\n");
break;

case 2:
q="SELECT students.Roll_No,students.Name,
marks.Internal_Marks FROM students LEFT OUTER JOIN marks ON students.Roll_No=marks.Roll_No;";

res=st.executeQuery(q);
System.out.println("\n\t----------------------------
---------------------------------------");
System.out.println("\n\t\t\t\tRECORDS");
System.out.println("\n\t--------------------------------
-----------------------------------\n");

while (res.next())
{
int rollno = res.getInt("Roll_No");
String name = res.getString("Name");
int Imarks = res.getInt("Internal_Marks");
System.out.println("\n\tRoll No:"+rollno+"\t Name:"+name+"\tInternal_Marks:"+Imarks+"\n");
}
System.out.println("\n\t-----------------------------------
--------------------------------\n");
break;

case 3:
q="SELECT students.department,marks.Roll_No,marks, External_Marks FROM students RIGHT OUTER JOIN marks ON students.Name=marks.Name;";

res=st.executeQuery(q);
System.out.println("\n\t--------------------------------
-----------------------------------");
System.out.println("\n\t\t\t\tRECORDS");
System.out.println("\n\t--------------------------------------
-----------------------------\n");

while (res.next())
{
String department = res.getString("Department");
int rollno = res.getInt("Roll_No");
int Emarks = res.getInt("External_Marks");
System.out.println("\n\tDepartment:"+
department +"Roll No:"+rollno+
"\tExternal Marks:"+Emarks+"\n");
}
System.out.println("\n\t-------------------------------------
------------------------------\n");
break;

case 4:
q="SELECT * FROM students LEFT OUTER JOIN marks ON students.Roll_No=marks.Roll_No UNION SELECT * FROM students RIGHT OUTER JOIN marks ON
students.Roll_No=marks.Roll_No;";

res=st.executeQuery(q);
System.out.println("\n\t---------------------------------
----------------------------------");
System.out.println("\n\t\t\t\tRECORDS"); System.out.println("\n\t------------------------------------
-------------------------------\n");
while (res.next())
{
int rollno = res.getInt("Roll_No");
String name = res.getString("Name");
int Imarks = res.getInt("Internal_Marks");
int Emarks = res.getInt("External_Marks");
System.out.println("\n\tRoll No:"+rollno+ "\tName:"+name+"\tInt_marks:"
+Imarks+"\tEx_marks:"+Emarks+"\n");
}
System.out.println("\n\t-----------------------------------
--------------------------------\n");
break;

case 5: break;
}
}while(ch!=5);
break;
case 4: System.exit(0);
}
}while(ch!=4);
}
catch(SQLException se)
{
System.out.print("\nCreated error is:\n"+se+"\n");
}
catch (Exception e)
{
System.out.print("\nCreated error is:\n"+e+"\n");
}
}
}

/*------------------------------------------------------------------------------------------------------

OUTPUT

In mysql -Server ;-

mysql> create database studinfo;
Query OK, 1 row affected (0.00 sec)

On Terminal-client:-

gescoe@gescoe:~/Desktop$ export CLASSPATH=$CLASSPATH:/usr/share/java/mysql-connector-java.jar
gescoe@gescoe:~/Desktop$ javac Javasql1.java
gescoe@gescoe:~/Desktop$ java Javasql1

---------MENU---------
1.Create Tables
2.Insert Records
3.Joins
4.Exit

Enter your choice:
1

Creating two table:student and marks

'students' and 'marks'table Successfully created

---------MENU---------
1.Create Tables
2.Insert Records
3.Joins
4.Exit

Enter your choice:
2

Inserted records into the tables 'students' and 'marks' successfully...

---------MENU---------
1.Create Tables
2.Insert Records
3.Joins
4.Exit

Enter your choice:
3

-------Joins-------
1.INNER JOIN
2.LEFT OUTER JOIN
3.RIGHT OUTER JOIN
4.FULL OUTER JOIN
5.Exit

Enter your choice:
1

------------------------------------------------------------------------------------
RECORDS
------------------------------------------------------------------------------------
Roll No:103 Name:Nishi Department:Computer
Roll No:174 Name:Anushka Department:Computer
Roll No:115 Name:Anuja Department:IT
------------------------------------------------------------------------------------


-------Joins-------
1.INNER JOIN
2.LEFT OUTER JOIN
3.RIGHT OUTER JOIN
4.FULL OUTER JOIN
5.Exit

Enter your choice:
2

-------------------------------------------------------------------------------
RECORDS
-------------------------------------------------------------------------------
Roll No:103 Name:Nishi Internal_Marks:38
Roll No:174 Name:Anushka Internal_Marks:43
Roll No:115 Name:Anuja Internal_Marks:30
Roll No:101 Name:Shubha Internal_Marks:0
Roll No:112 Name:Rohini Internal_Marks:0
-------------------------------------------------------------------------------

-------Joins-------
1.INNER JOIN
2.LEFT OUTER JOIN
3.RIGHT OUTER JOIN
4.FULL OUTER JOIN
5.Exit

Enter your choice:
3

------------------------------------------------------------------------------------------------
RECORDS
------------------------------------------------------------------------------------------------
Department:Computer Roll No:103 External Marks:43
Department:Computer Roll No:174 External Marks:45
Department:IT Roll No:115 External Marks:34
Department:null Roll No:133 External Marks:39
Department:null Roll No:111 External Marks:41
------------------------------------------------------------------------------------------------

-------Joins-------
1.INNER JOIN
2.LEFT OUTER JOIN
3.RIGHT OUTER JOIN
4.FULL OUTER JOIN
5.Exit

Enter your choice:
4
--------------------------------------------------------------------------------------------------
RECORDS
--------------------------------------------------------------------------------------------------
Roll No:103 Name:Nishi Int_marks:38 Ex_marks:43
Roll No:174 Name:Anushka Int_marks:43 Ex_marks:45
Roll No:115 Name:Anuja Int_marks:30 Ex_marks:34
Roll No:101 Name:Shubha Int_marks:0 Ex_marks:0
Roll No:112 Name:Rohini Int_marks:0 Ex_marks:0
Roll No:0 Name:null Int_marks:35 Ex_marks:39
Roll No:0 Name:null Int_marks:40 Ex_marks:41
---------------------------------------------------------------------------------------------------



-------Joins-------
1.INNER JOIN
2.LEFT OUTER JOIN
3.RIGHT OUTER JOIN
4.FULL OUTER JOIN
5.Exit

Enter your choice:
5

---------MENU---------
1.Create Tables
2.Insert Records
3.Joins
4.Exit

Enter your choice:
4

gescoe@gescoe:~/Desktop$ */







===============================

Practical: A3 Two tier client server mysql

===============================



 /************ ON SERVER PC ****************/


gescoe@gescoe:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 38
Server version: 5.5.38-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.





mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| DMSA               |
| T4                 |
| TE4                |
| Te40               |
| mysql              |
| performance_schema |
+--------------------+
7 rows in set (0.03 sec)


mysql> use TE4
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed



mysql> show tables;
+---------------+
| Tables_in_TE4 |
+---------------+
| PLI           |
| Student       |
| cdept         |
| compdept      |
| stud          |
+---------------+
5 rows in set (0.00 sec)




mysql> select * from Student;
+--------+--------+------------+---------+
| Rollno | Name   | Branch     | Percent |
+--------+--------+------------+---------+
|      2 | ANUSHA | IT         |      75 |
|      3 | Veena  | Mechanical |      60 |
|      4 | ANUSHA | Computer   |      60 |
|      5 | Sahil  | Civil      |      60 |
+--------+--------+------------+---------+
4 rows in set (0.00 sec)



mysql> create view cd1 as select Rollno,Name,Percent from Student where Branch='Computer';    //create view "cd1"
Query OK, 0 rows affected (0.04 sec)



mysql> select * from cd1;        //display entries
+--------+--------+---------+
| Rollno | Name   | Percent |
+--------+--------+---------+
|      4 | ANUSHA |      60 |
+--------+--------+---------+
1 row in set (0.00 sec)



mysql> select * from cd1;    //display table cd1 after performing various operations by client pc
Empty set (0.00 sec)




mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| DMSA               |
| T4                 |
| TE4                |
| Te40               |
| mysql              |
| performance_schema |
+--------------------+
7 rows in set (0.03 sec)



mysql> use TE4;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed



mysql> show tables;
+---------------+
| Tables_in_TE4 |
+---------------+
| PLI           |
| REGISTRATION  |
| Student       |
| cd            |
| cd1           |
| cdept         |
| compdept      |
| stud          |
+---------------+
8 rows in set (0.00 sec)




mysql> create index cdindx on Student (Name);        //create INDEX on coloumn 'Name'
Query OK, 0 rows affected (0.18 sec)
Records: 0  Duplicates: 0  Warnings: 0



mysql>





/************** CLIENT **************************/



gescoe@gescoe:~$ mysql -u userall -h 192.168.2.223
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 40
Server version: 5.5.38-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.




mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| DMSA               |
| T4                 |
| TE4                |
| Te40               |
| mysql              |
| performance_schema |
+--------------------+
7 rows in set (0.00 sec)




mysql> use TE4
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed



mysql> show tables;
+---------------+
| Tables_in_TE4 |
+---------------+
| PLI           |
| Student       |
| cd            |
| cd1           |
| cdept         |
| compdept      |
| stud          |
+---------------+
7 rows in set (0.00 sec)




mysql> select * from cd1;
+--------+--------+---------+
| Rollno | Name   | Percent |
+--------+--------+---------+
|      4 | ANUSHA |      60 |
+--------+--------+---------+
1 row in set (0.00 sec)



mysql> update cd1 set Name='Navin' where Name='Anusha';  //UPDATE
Query OK, 1 row affected (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 0




mysql> select * from cd1;
+--------+-------+---------+
| Rollno | Name  | Percent |
+--------+-------+---------+
|      4 | Navin |      60 |
+--------+-------+---------+
1 row in set (0.00 sec)




mysql> delete from cd1 where Rollno=4;  //DELETE
Query OK, 1 row affected (0.05 sec)



mysql> select * from cd1;
Empty set (0.00 sec)



===============================

Practical: A4 i-node

===============================



/*-------------------------------------------------------------------------------
Assigment no. :04
Group :A
Title :Write a program in Python/C++ to read display the i-node information for a given text file,
    image file.
Roll No. :
Batch :
------------------------------------------------------------------------------- */



#include<iostream>
#include<fstream>
#include<sys/stat.h>
using namespace std;
class osd1
{
    private:
        char filename[20];
        struct stat buf;
    public:
       
        void get_filename()
        {
            cout<<"\n\t Enter the name of file : ";
            cin>>filename;
        }

        void create_file()
        {
            ofstream write(filename);
            if(write.is_open())
            {
                cout<<"\n\n\t File "<<filename<<"  has been created successfully..\n\n";
                write.close();
            }
            else
            {
                cout<<"\n\n\t File "<<filename<<"  has been not created..\n\n";
            }
        }

        void display_data()
        {
            cout<<"\n\t--------------------------";
            cout<<"\n\t     FILE DETAILS....";
            cout<<"\n\t--------------------------";
            cout<<"\n\n\t Name : "<<filename;
            stat(filename,&buf);
            cout<<"\n\t Inode : "<<buf.st_ino;
            cout<<"\n\t Size : "<<buf.st_size<<"\n\n";
        }
};
int main()
{
    osd1 o;
    o.get_filename();
    o.create_file();
    o.display_data();
    return 0;
}





/*
-----------------------------------------
       OUTPUT
-----------------------------------------


administrator@administrator-Vostro-230:~$ cd Desktop/TE_73/
administrator@administrator-Vostro-230:~/Desktop/TE_73$ g++ osd1.cpp -o osd1
administrator@administrator-Vostro-230:~/Desktop/TE_73$ ./osd1

     Enter the name of file : navin


     File navin  has been created successfully..


    --------------------------
         FILE DETAILS....
    --------------------------

     Name : navin
     Inode : 18612477
     Size : 0

administrator@administrator-Vostro-230:~/Desktop/TE_73$ stat navin
  File: `navin'
  Size: 0             Blocks: 0          IO Block: 4096   regular empty file
Device: 801h/2049d    Inode: 18612477    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/administrator)   Gid: ( 1000/administrator)
Access: 2014-07-01 11:18:12.956589503 +0530
Modify: 2014-07-01 11:18:11.840589506 +0530
Change: 2014-07-01 11:18:11.840589506 +0530
 Birth: -
administrator@administrator-Vostro-230:~/Desktop/TE_73$


*/



===============================

Practical: A5 IPC Program using pipe

===============================



-------------------------------------------------------------------------------
Assigment no. :05
Group :A
Title :Write an IPC program using pipe. Process A accepts a character string and Process B
    inverses the string. Pipe is used to establish communication between A and B processes
    using Python or C++
Roll No. :
Batch :
-------------------------------------------------------------------------------







**** processA.py ******


import os
wfpath="./p1"
rfpath="./p1"
wp=open(wfpath,'w')
wp.write("hello")
wp.close
rp=open(rfpath,'r')
response=rp.read()
print"Reverse of string from process B : %s"%response



***** processB.py *****


import os
rfpath="./p1"
wfpath="./p2"
try:
    os.mkfifo(wfpath)
    os.mkfifo(rfpath)
except OSError:
    pass
rp=open(rfpath,'r')
response=rp.read()
print"String recieved from Process A : %s"%response
s=response
s=s[::-1]
print"Reverse is :%s"%s
rp.close()
wp=open(wfpath,'w')
wp.write(s)
wp.close()
rp.close()




****input : p1.txt ****



hello


----------------------------------------------------
        OUTPUT
----------------------------------------------------


navin@Navin:~/Desktop$ python processA.py
Reverse of string from process B :
navin@Navin:~/Desktop$ python processB.py
String recieved from Process A : hello
Reverse is :olleh



===============================

Practical: A6

===============================

 

**** server ****

 

 # Server program
from socket import *

# Set the socket parameters

host = "192.168.1.72"
port = 8080
buf = 1024
addr = (host,port)
# Create socket and bind to address

UDPSock = socket(AF_INET,SOCK_DGRAM)
UDPSock.bind(addr)
# Receive messages

while 1:
    data,addr = UDPSock.recvfrom(buf)
    if not data:
        print "Client has exited!"
        break
    else:
        print "Received message '", data,"'"
# Close socket

UDPSock.close()


 

**** client **** 

# Client program
from socket import *

# Set the socket parameters

host = "localhost"
port = 21567
buf = 1024
addr = (host,port)
# Create socket

UDPSock = socket(AF_INET,SOCK_DGRAM)
def_msg = "===Enter message to send to server===";

print "",def_msg
# Send messages

while (1):
    data = raw_input('>> ')
    if not data:
        break
    else:
        if(UDPSock.sendto(data,addr)):
            print "Sending message '",data,"'....."
# Close socket

UDPSock.close()



===============================

Practical: b1 Three tier mysql

===============================

 

//PROGRAM:

import java.lang.*;
import java.sql.*;
import java.io.*;

public class Javasql
{
public static void main(String[] args)
{
int ch;
String q;
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String url = "jdbc:mysql://localhost/";
String driver = "com.mysql.jdbc.Driver";
String dbName = "company";
String userName = "root";
String password="gescoe";

try{

Connection conn = DriverManager.getConnection(url+dbName,userName,password);
Statement st = conn.createStatement();
do
{

System.out.println("\n---------MENU---------");
System.out.println("\n1.Create Table");
System.out.println("\n2.Insert Records");
System.out.println("\n3.Select Table");
System.out.println("\n4.Update record");
System.out.println("\n5.Aggregation Function for Table");
System.out.println("\n6.Delete records");
System.out.println("\n7.Drop Table");
System.out.println("\n8.Exit");
System.out.println("\n\nEnter your choice:");
ch=Integer.parseInt(input.readLine());

switch(ch)
{
case 1:
q="CREATE TABLE products(productID INT PRIMARY KEY, Name VARCHAR(15),Quantity INT,Price DECIMAL(7,2))";
st.executeUpdate(q);

System.out.println("\n'products' table Successfully created\n");
break;

case 2:
q = "INSERT INTO products"+" VALUES(1351,'Monitor',2000,10000)";
st.executeUpdate(q);
q = "INSERT INTO products"+" VALUES(1352,'Keyboard',2000,3000);";
st.executeUpdate(q);
q = "INSERT INTO products "+"VALUES(1353,'CPU',5600,8000);";
st.executeUpdate(q);
q = "INSERT INTO products "+"VALUES(1354,'Harddisk',500,3000);";
st.executeUpdate(q);
q = "INSERT INTO products "+"VALUES(1355,'USB',1500,500);";
st.executeUpdate(q);

System.out.println("\nRecords inserted into the table 'products'...\n");
break;

case 3:
ResultSet res = st.executeQuery("SELECT * FROM products");
System.out.println("\n\nTable:product\n");
System.out.println("\n\t-----------------------------------------------------------");
System.out.println("\n\t\t\t\tRECORDS");
System.out.println("\n\t---------------------------------------------------------\n");
while (res.next()) {
int id = res.getInt("productID");
String name = res.getString("Name");
int quan = res.getInt("Quantity");
int price = res.getInt("Price");
System.out.println("\n\tProductID:"+id+"\t\tName:"+name+ "\tQuantity:"+quan+"\tPrice:"+price+"\n");
}
System.out.println("\n\t--------------------------------------------------------\n");

break;

case 4:
q ="UPDATE products SET Price=10000 where Name='CPU'; ";
st.executeUpdate(q);
System.out.println("\nRecord is updated where Name='CPU'");
break;

case 5:
do{
System.out.println("\n\n------Aggregation Functions------\n");
System.out.println("\n1.count()");
System.out.println("\n2.sum()");
System.out.println("\n3.max()");
System.out.println("\n4.min()");
System.out.println("\n5.avg()");
System.out.println("\n6.Exit");
System.out.println("\n\nEnter your choice:");
ch=Integer.parseInt(input.readLine());
switch(ch)
{
case 1:
q="SELECT count(Name) as 'Total products' FROM products;";
res=st.executeQuery(q);
while (res.next())
{
int total = res.getInt("Total Products");
System.out.println("\n\tTotal products is:"+total+"\n");
}

break;

case 2:
q="SELECT sum(Quantity)as 'Total Quantity' FROM products;";
res=st.executeQuery(q);
while (res.next())
{
int total = res.getInt("Total Quantity");
System.out.println("\n\tTotal products Quantity:" +total+"\n");
}

break;

case 3:
q="SELECT * FROM products WHERE Quantity= (SELECT max(Quantity) FROM products);";
res=st.executeQuery(q);
System.out.println("\n\t---------------------------------------------------");
System.out.println("\n\t\t\t\tRECORDS");
System.out.println("\n\t------------------------------------------------\n");
while (res.next())
{
int id = res.getInt("productID");
String name = res.getString("Name");
int quan = res.getInt("Quantity");
int price = res.getInt("Price");
System.out.println("\n\tProductID:"+id+"\t\tName:" +name+"\tQuantity:"+quan+"\tPrice:"+price+"\n");
}
System.out.println("\n\t-------------------------------------------------\n");
break;

case 4:
q="SELECT * FROM products WHERE Price=(SELECT min(Price) FROM products);";
res=st.executeQuery(q);
System.out.println("\n\t--------------------------------------------------");
System.out.println("\n\t\t\t\tRECORDS");
System.out.println("\n\t-------------------------------------------------\n");
while (res.next())
{
int id = res.getInt("productID");
String name = res.getString("Name");
int quan = res.getInt("Quantity");
int price = res.getInt("Price");
System.out.println("\n\tProductID:"+id+"\t\tName:"+name+ "\tQuantity:"+quan+"\tPrice:"+price+"\n");
}
System.out.println("\n\t-------------------------------------------------\n");
break;

case 5:
q="SELECT DISTINCT Name FROM products WHERE Price>(SELECT AVG(Price) FROM products);";
res=st.executeQuery(q);
System.out.println("\n\t---------------------------------------------------");
System.out.println("\n\t\t\t\tRECORDS");
System.out.println("\n\t-------------------------------------------------\n");
while (res.next())
{
String name = res.getString("Name");
System.out.println("\n\tName:"+name+"\n");

}
System.out.println("\n\t-------------------------------------------------\n");
break;

case 6: break;
}
}while(ch!=6);
break;



case 6:
q="DELETE FROM products;";
st.executeUpdate(q);
System.out.println("\n'products' table is empty...\n");

break;

case 7:
q="DROP TABLE products;";
st.executeUpdate(q);
System.out.println("\n 'products' table are deleted successfully...\n");
break;

case 8: System.exit(0);
}
}while(ch!=8);
}
catch(SQLException se)
{
System.out.print("\nCreated error is:\n"+se+"\n");
}
catch (Exception e)
{
System.out.print("\nCreated error is:\n"+e+"\n");
}
}
}

/*--------------------------------------------------------------------------------------------------------------
OUTPUT:

gescoe@gescoe:~/Desktop$ export CLASSPATH=$CLASSPATH:/usr/share/java/mysql-connector-java.jar
gescoe@gescoe:~/Desktop$ javac Javasql.java
gescoe@gescoe:~/Desktop$ java Javasql

---------MENU---------
1.Create Table
2.Insert Records
3.Select Table
4.Update record
5.Aggregation Function for Table
6.Delete records
7.Drop Table
8.Exit

Enter your choice:
1

'products' table Successfully created

---------MENU---------
1.Create Table
2.Insert Records
3.Select Table
4.Update record
5.Aggregation Function for Table
6.Delete records
7.Drop Table
8.Exit

Enter your choice:
2

Records inserted into the table 'products'...

---------MENU---------
1.Create Table
2.Insert Records
3.Select Table
4.Update record
5.Aggregation Function for Table
6.Delete records
7.Drop Table
8.Exit

Enter your choice:
3


Table:product

----------------------------------------------------------------------------------------------------------
RECORDS
---------------------------------------------------------------------------------------------------------

Product ID:1351 Name:Monitor Quantity:2000 Price:10000
Product ID:1352 Name:Keyboard Quantity:2000 Price:3000
Product ID:1353 Name:CPU Quantity:5600 Price:8000
Product ID:1354 Name:Harddisk Quantity:500 Price:3000
Product ID:1355 Name:USB Quantity:1500 Price:500
---------------------------------------------------------------------------------------------------------

---------MENU---------
1.Create Table
2.Insert Records
3.Select Table
4.Update record
5.Aggregation Function for Table
6.Delete records
7.Drop Table
8.Exit

Enter your choice:
4

Record is updated where Name='CPU'

---------MENU---------
1.Create Table
2.Insert Records
3.Select Table
4.Update record
5.Aggregation Function for Table
6.Delete records
7.Drop Table
8.Exit

Enter your choice:
5

------Aggregation Functions------
1.count()
2.sum()
3.max()
4.min()
5.avg()
6.Exit

Enter your choice:
1

Total products is:5

------Aggregation Functions------
1.count()
2.sum()
3.max()
4.min()
5.avg()
6.Exit

Enter your choice:
2

Total products Quantity:11600

------Aggregation Functions------
1.count()
2.sum()
3.max()
4.min()
5.avg()
6.Exit

Enter your choice:
3

------------------------------------------------------------------------------------------
RECORDS
------------------------------------------------------------------------------------------

Product ID:1353 Name:CPU Quantity:5600 Price:10000
------------------------------------------------------------------------------------------

------Aggregation Functions------
1.count()
2.sum()
3.max()
4.min()
5.avg()
6.Exit

Enter your choice:
4


--------------------------------------------------------------------------------------
RECORDS
--------------------------------------------------------------------------------------
Product ID:1355 Name:USB Quantity:1500 Price:500
--------------------------------------------------------------------------------------


------Aggregation Functions------
1.count()
2.sum()
3.max()
4.min()
5.avg()
6.Exit

Enter your choice:
5

-------------------------------------------------------------------
RECORDS
-------------------------------------------------------------------
Name:Monitor
Name:CPU
-------------------------------------------------------------------

------Aggregation Functions------
1.count()
2.sum()
3.max()
4.min()
5.avg()
6.Exit

Enter your choice:
6

---------MENU---------
1.Create Table
2.Insert Records
3.Select Table
4.Update record
5.Aggregation Function for Table
6.Delete records
7.Drop Table
8.Exit

Enter your choice:
6

'products' table is empty...

---------MENU---------
1.Create Table
2.Insert Records
3.Select Table
4.Update record
5.Aggregation Function for Table
6.Delete records
7.Drop Table
8.Exit

Enter your choice:
7

'products' table are deleted successfully...

---------MENU---------
1.Create Table
2.Insert Records
3.Select Table
4.Update record
5.Aggregation Function for Table
6.Delete records
7.Drop Table
8.Exit

Enter your choice:
8
gescoe@gescoe:~/Desktop$
*/







===============================

Practical: B2 mongodb basics

===============================



gescoe@gescoe:~$ mongo
MongoDB shell version: 2.6.4
connecting to: test


> show dbs                        //Show database
TE     0.078GB
admin  (empty)
local  0.078GB
test   0.078GB


> use PN                        //create/use databases
switched to db PN


> db                            //to check working database
PN

------------------------------------------------------------------------------


> db.movie.insert({"name":"Pranav"})            //create collection while inserting data
WriteResult({ "nInserted" : 1 })


> show dbs
PN     0.078GB
TE     0.078GB
admin  (empty)
local  0.078GB
test   0.078GB


> db.createCollection("PRNV")                //create collection
{ "ok" : 1 }


> show collections                    //display collections
PRNV
movie
system.indexes



------------------------------------------------------------------------------

> db.movie.drop()                    //drop collections
true


> show collections                    //display collections
PRNV
system.indexes


------------------------------------------------------------------------------


> db.PRNV.insert({Name: 'NAVIN WAGHWANI',Rno:73,Branch:'Computer' })    //insert entries in collection
WriteResult({ "nInserted" : 1 })

> db.PRNV.insert({Name: 'PRANAV LAWATE',Rno:40,Branch:'IT' })
WriteResult({ "nInserted" : 1 })

> db.PRNV.insert({Name: 'ANUSHA PINGALE',Rno:60,Branch:'MECH' })
WriteResult({ "nInserted" : 1 })


------------------------------------------------------------------------------


> db.PRNV.find()                    //display all records
{ "_id" : ObjectId("541419673a244ede65d8482c"), "Name" : "NAVIN WAGHWANI", "Rno" : 73, "Branch" : "Computer" }
{ "_id" : ObjectId("541419873a244ede65d8482d"), "Name" : "PRANAV LAWATE", "Rno" : 40, "Branch" : "IT" }
{ "_id" : ObjectId("541419aa3a244ede65d8482e"), "Name" : "ANUSHA PINGALE", "Rno" : 60, "Branch" : "MECH" }


------------------------------------------------------------------------------



> db.PRNV.update({'Branch':'IT'},{$set:{'Branch':'Computer'}})        //Update using same fields
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })


> db.PRNV.find()                           
{ "_id" : ObjectId("541419673a244ede65d8482c"), "Name" : "NAVIN WAGHWANI", "Rno" : 73, "Branch" : "Computer" }
{ "_id" : ObjectId("541419873a244ede65d8482d"), "Name" : "PRANAV LAWATE", "Rno" : 40, "Branch" : "Computer" }
{ "_id" : ObjectId("541419aa3a244ede65d8482e"), "Name" : "ANUSHA PINGALE", "Rno" : 60, "Branch" : "MECH" }


> db.PRNV.update({'Name':'NAVIN WAGHWANI'},{$set:{'Branch':'Mechanical'}})        //Update using different fileds
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })


> db.PRNV.find()                           
{ "_id" : ObjectId("541419673a244ede65d8482c"), "Name" : "NAVIN WAGHWANI", "Rno" : 73, "Branch" : "Mechanical" }
{ "_id" : ObjectId("541419873a244ede65d8482d"), "Name" : "PRANAV LAWATE", "Rno" : 40, "Branch" : "Computer" }
{ "_id" : ObjectId("541419aa3a244ede65d8482e"), "Name" : "ANUSHA PINGALE", "Rno" : 60, "Branch" : "MECH" }



------------------------------------------------------------------------------


> db.PRNV.remove({'Rno':60})                        //Remove entry
WriteResult({ "nRemoved" : 1 })


> db.PRNV.find()
{ "_id" : ObjectId("541419673a244ede65d8482c"), "Name" : "NAVIN WAGHWANI", "Rno" : 73, "Branch" : "Computer" }
{ "_id" : ObjectId("541419873a244ede65d8482d"), "Name" : "PRANAV LAWATE", "Rno" : 40, "Branch" : "Computer" }


> db.PRNV.find().pretty()
{
    "_id" : ObjectId("541419673a244ede65d8482c"),
    "Name" : "NAVIN WAGHWANI",
    "Rno" : 73,
    "Branch" : "Computer"
}
{
    "_id" : ObjectId("541419873a244ede65d8482d"),
    "Name" : "PRANAV LAWATE",
    "Rno" : 40,
    "Branch" : "Computer"
}


===============================

Practical: B5 BIOS

===============================


-------------------------------------------------------------------------------
Assigment no. :05
Group :B
Title :Write a program in Python/C++ to test that computer is booted with Legacy Boot ROM-
    BIOS or UEFI.
Roll No. :
Batch :
-------------------------------------------------------------------------------


#include <iostream>
#include <stdlib.h>
#include <sys/stat.h>

using namespace std;

int main()
{
    cout<<"\n\nHARDWARE BOOTED FROM...\n\n";
    system("[ -d /sys/firmware/efi ] && echo UEFI || echo BIOS");
    return 0;
}

/***** OUTPUT *****

root@administrator-Vostro-230:/home/administrator/Desktop# g++ bios.cpp -o bios.o
root@administrator-Vostro-230:/home/administrator/Desktop# ./bios.o

HARDWARE BOOTED FROM...

BIOS

*/


===============================

Practical: B6 RAMDRIVE

===============================


-------------------------------------------------------------------------------
Assigment no. :06
Group :B
Title :Write a program in C++ to create a RAMDRIVE and associate an acyclic directory structure
    to it. Use this RAMDRIVE to store input, out files to run a calculator program.
Roll No. :
Batch :
-------------------------------------------------------------------------------



 

****** calc.cpp *****



#include<iostream>
using namespace std;
int main()
{
    float no1,no2,res;
    int ch;
    cout<<"\n-----------------------------------------------------------";
    cout<<"\n\n\t\t ***** CALCULATOR *****";
    cout<<"\n-----------------------------------------------------------";
    cout<<"\n\n\t Enter first number : ";
    cin>>no1;
    cout<<"\n\n\t Enter second number : ";
    cin>>no2;
    do
    {
        cout<<"\n\n\t\t ***** MENU *****";
        cout<<"\n\n\t 1]. Addition";
        cout<<"\n\t 2]. Subtraction";
        cout<<"\n\t 3]. Multilication";
        cout<<"\n\t 4]. Division";
        cout<<"\n\t 5]. Mod";
        cout<<"\n\t 6]. Exit";
        cout<<"\n\n\t\t Enter your choice : ";
        cin>>ch;
        switch(ch)
        {
            case 1: res=no1+no2;
                cout<<"\n\t Addition of two numbers is : "<<res;
                break;
            case 2: res=no1-no2;
                cout<<"\n\t Subtraction of two numbers is : "<<res;
                break;
            case 3: res=no1*no2;
                cout<<"\n\t Multiplication of two numbers is : "<<res;
                break;
            case 4: res=no1/no2;
                cout<<"\n\t Division of two numbers is : "<<res;
                break;
            case 5: res=no1%no2;
                cout<<"\n\t Modulus of two numbers is : "<<res;
                break;
            case 6:return 1;
                break;
        }
    }while(ch!=6);
    return 0;
}


**** navin.cpp ****



#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{   
    system("sudo mkdir -p /media/rdcal123");
    system("sudo mount -t tmpfs -o size=512M tmpfs /media/rdcal123");
    system("sudo cp /home/administrator/Desktop/calc.cpp /media/rdcal123/");   
    system("sudo g++ calc.cpp -o a.o");
    system("./a.o");
return 0;   
}


/*========= OUTPUT ==========


root@administrator-Vostro-230:/home/administrator/Desktop# g++ navin.cpp -o navin.o
root@administrator-Vostro-230:/home/administrator/Desktop# ./navin.o
calc.cpp: In function ‘int main()’:
calc.cpp:39:20: error: invalid operands of types ‘float’ and ‘float’ to binary ‘operator%’

-----------------------------------------------------------

         ***** CALCULATOR *****
-----------------------------------------------------------

     Enter first number : 5


     Enter second number : 2


         ***** MENU *****

     1]. Addition
     2]. Subtraction
     3]. Multilication
     4]. Division
     5]. Mod
     6]. Exit

         Enter your choice : 1

     Addition of two numbers is : 7

         ***** MENU *****

     1]. Addition
     2]. Subtraction
     3]. Multilication
     4]. Division
     5]. Mod
     6]. Exit

         Enter your choice : 2

     Subtraction of two numbers is : 3

         ***** MENU *****

     1]. Addition
     2]. Subtraction
     3]. Multilication
     4]. Division
     5]. Mod
     6]. Exit

         Enter your choice : 3

     Multiplication of two numbers is : 10

         ***** MENU *****

     1]. Addition
     2]. Subtraction
     3]. Multilication
     4]. Division
     5]. Mod
     6]. Exit

         Enter your choice : 4

     Division of two numbers is : 2.5

         ***** MENU *****

     1]. Addition
     2]. Subtraction
     3]. Multilication
     4]. Division
     5]. Mod
     6]. Exit

         Enter your choice : 5


         ***** MENU *****

     1]. Addition
     2]. Subtraction
     3]. Multilication
     4]. Division
     5]. Mod
     6]. Exit

         Enter your choice : 6
root@administrator-Vostro-230:/home/administrator/Desktop#

*/





===============================

Practical: B12  USB Device bootable

===============================

-------------------------------------------------------------------------------
Assigment no. :12
Group :B
Title :Write a program in C++ to make USB Device Bootable by installing required system files.
Roll No. :
Batch :
-------------------------------------------------------------------------------




#include <iostream>
#include <stdlib.h>
#include <sys/stat.h>
using namespace std;
int main()
{
    char Ans;
    int N;
re:    cout<<"\n\nPlease Insert The Pendrive Now...";
    cout<<"\n\nHave You Inserted The Pendrive ? [Y/N]";
    cin>>Ans;
    if(Ans=='y' || Ans=='Y')
    {
        system("sudo lsusb");       
        cout<<"\n\nIs The Pendrive Visible ? [Y/N]";
        cin>>Ans;       
        if(Ans=='y' || Ans=='Y')
        {
            cout<<"\n\nEntering Root Mode...\n\n";       
            cout<<"\n\nCopying System Files...\n\n";       
            system("sudo dd if=/home/gescoe/Documents/ubuntu.iso of=/dev/sdb && sync");
        }
        else
        {
            cout<<"\n\nPlease re-attach the pendrive and try again...\n\n";
            goto re;
        }
        cout<<"\n\nAll Done! Ready To Boot...\n\n";               
    }   
    else
    {
        goto re;   
    }
return 0;
}
/***************** OUtput **************
root@gescoe:/home/gescoe/Desktop/pd_navin# g++ btpd.cpp -o btpd
root@gescoe:/home/gescoe/Desktop/pd_navin# ./btpd
Please Insert The Pendrive Now...
Have You Inserted The Pendrive ? [Y/N]y
Bus 002 Device 004: ID 0461:4e22 Primax Electronics, Ltd
Bus 002 Device 003: ID 413c:2107 Dell Computer Corp.
Bus 002 Device 006: ID 8644:800b 
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Is The Pendrive Visible ? [Y/N]y
Entering Root Mode...
Copying System Files...
2009088+0 records in
2009088+0 records out
1028653056 bytes (1.0 GB) copied, 4.31832 s, 238 MB/s
All Done! Ready To Boot...
root@gescoe:/home/gescoe/Desktop/pd_navin#
*/

===============================

Practical: B mongodbaggregation

===============================

 gescoe@gescoe:~$ mongo
MongoDB shell version: 2.6.4
connecting to: test
> show dbs;
admin     (empty)
computer  0.078GB
mymdb     0.078GB
t4        0.078GB
> use myddb
switched to db myddb
_____________________________________________________________________
CREATE COLLECTION:
____________________________________________________________________
CMD:db.createCollection("student");
{ "ok" : 1 }
CMD:
   db.student.insert({Rollno:1,name:'Navin ',subject:'DMSA',marks:78});
   WriteResult({ "nInserted" : 1 })
   db.student.insert({Rollno:2,name:'anusha',subject:'OSD',marks:75});
   WriteResult({ "nInserted" : 1 })
   db.student.insert({Rollno:3,name:'ravi',subject:'TOC',marks:69});
   WriteResult({ "nInserted" : 1 })
   db.student.insert({Rollno:4,name:'veena',subject:'TOC',marks:70});
   WriteResult({ "nInserted" : 1 })
_____________________________________________________________________
DISPALY RECORD:
_____________________________________________________________________
CMD: db.student.find();

{ "_id" : ObjectId("541bffb74ebca325353a6529"), "Rollno" : 1, "name" : "Navin", "subject" : "DMSA", "marks" : 78 }
{ "_id" : ObjectId("541bffd34ebca325353a652a"), "Rollno" : 2, "name" : "anusha", "subject" : "OSD", "marks" : 75 }
{ "_id" : ObjectId("541c00134ebca325353a652b"), "Rollno" : 3, "name" : "ravi", "subject" : "TOC", "marks" : 69 }
{ "_id" : ObjectId("541c00134ebca325353a652b"), "Rollno" : 4, "name" : "veena", "subject" : "TOC", "marks" : 70 }

CMD:db.student.find().pretty();
{
    "_id" : ObjectId("541bffb74ebca325353a6529"),
    "Rollno" : 1,
    "name" : "Navin",
    "subject" : "DMSA",
    "marks" : 78
}
{
    "_id" : ObjectId("541bffd34ebca325353a652a"),
    "Rollno" : 2,
    "name" : "anusha",
    "subject" : "OSD",
    "marks" : 75
}
{
    "_id" : ObjectId("541c00134ebca325353a652b"),
    "Rollno" : 3,
    "name" : "ravi",
    "subject" : "TOC",
    "marks" : 69
}
{
    "_id" : ObjectId("541e00134ebca325353a652b"),
    "Rollno" : 4,
    "name" : "veena",
    "subject" : "TOC",
    "marks" : 70
}
_______________________________________________________________________________
AGGREGATE FUNCTIONS:
__________________________________________________________________________________
MIN():
CMD: db.student.aggregate([{$group : {_id : "$subject", marks : {$min : "$marks"}}}]);

{ "_id" : "TOC", "marks" : 70 }
{ "_id" : "OSD", "marks" : 75 }
{ "_id" : "DMSA", "marks" : 78 }
_________________________________________________________________________________
MAX():
CMD:db.student.aggregate([{$group : {_id : "$subject", marks : {$max : "$marks"}}}]);

{ "_id" : "TOC", "marks" : 69 }
{ "_id" : "OSD", "marks" : 75 }
{ "_id" : "DMSA", "marks" : 78 }
_________________________________________________________________________________
SUM():
CMD:db.student.aggregate([{$group : {_id : "$subject", marks : {$sum : "$marks"}}}]);
{ "_id" : "TOC", "marks" : 139 }
{ "_id" : "OSD", "marks" : 75 }
{ "_id" : "DMSA", "marks" : 78 }
__________________________________________________________________________________
AVG():
CMD:db.student.aggregate([{$group : {_id : "$subject", marks : {$avg : "$marks"}}}]);
{ "_id" : "TOC", "marks" : 69.5 }
{ "_id" : "OSD", "marks" : 75 }
{ "_id" : "DMSA", "marks" : 78 }
___________________________________________________________________________________
FIRST():
CMD:db.student.aggregate([{$group : {_id : "$subject", marks : {$first : "$marks"}}}]);
{ "_id" : "TOC", "marks : 69 }
{ "_id" : "OSD", "marks" : 75 }
{ "_id" : "DMSA", "marks" : 78 }
___________________________________"______________________________________________
LAST():
CMD:db.student.aggregate([{$group : {_id : "$subject", marks : {$last : "$marks"}}}]);
{ "_id" : "TOC", "marks" : 70 }
{ "_id" : "OSD", "marks" : 75 }
{ "_id" : "DMSA", "marks" : 78 }
___________________________________________________________________________________




===============================

Practical: B mongodb indexing

===============================


gescoe@gescoe:~$ mongo
MongoDB shell version: 2.6.4
connecting to: test
> show dbs
TE        0.078GB
admin     (empty)
computer  0.078GB
gj        0.078GB
local     0.078GB
mydb      0.078GB
mymdb     0.078GB
t4        0.078GB
> use mydb
switched to db mydb

//CREATE COLLECTION:
> db.createCollection("student");
{ "ok" : 1 }
> db.student.insert({Rollno:1,name:'nikita',subject:'DMSA',marks:78});
WriteResult({ "nInserted" : 1 })
> db.student.insert({Rollno:2,name:'kiran',subject:'OSD',marks:75});
WriteResult({ "nInserted" : 1 })
> db.student.insert({Rollno:3,name:'komal',subject:'TOC',marks:69});
WriteResult({ "nInserted" : 1 })
> db.student.insert({Rollno:4,name:'snehal',subject:'TOC',marks:81});
WriteResult({ "nInserted" : 1 })
> db.student.insert({Rollno:5,name:'saurabh',subject:'TOC',marks:78});
WriteResult({ "nInserted" : 1 })

//DISPLAY COLLECTION:
> db.student.find();
{ "_id" : ObjectId("541bffb74ebca325353a6529"), "Rollno" : 1, "name" : "nikita", "subject" : "DMSA", "marks" : 78 }
{ "_id" : ObjectId("541bffd34ebca325353a652a"), "Rollno" : 2, "name" : "kiran", "subject" : "OSD", "marks" : 75 }
{ "_id" : ObjectId("541c00134ebca325353a652b"), "Rollno" : 3, "name" : "komal", "subject" : "TOC", "marks" : 69 }
{ "_id" : ObjectId("541c00274ebca325353a652c"), "Rollno" : 4, "name" : "snehal", "subject" : "TOC", "marks" : 81 }
{ "_id" : ObjectId("541c007c4ebca325353a652d"), "Rollno" : 5, "name" : "saurabh", "subject" : "TOC", "marks" : 78 }

> db.student.find().pretty();
{
    "_id" : ObjectId("541bffb74ebca325353a6529"),
    "Rollno" : 1,
    "name" : "nikita",
    "subject" : "DMSA",
    "marks" : 78
}
{
    "_id" : ObjectId("541bffd34ebca325353a652a"),
    "Rollno" : 2,
    "name" : "kiran",
    "subject" : "OSD",
    "marks" : 75
}
{
    "_id" : ObjectId("541c00134ebca325353a652b"),
    "Rollno" : 3,
    "name" : "komal",
    "subject" : "TOC",
    "marks" : 69
}

{
    "_id" : ObjectId("541c0e05a8dc3dd4fa9f859e"),
    "Rollno" : 4,
    "name" : "snehal",
    "subject" : "TOC",
    "marks" : 81
}
{
    "_id" : ObjectId("541c0e2ca8dc3dd4fa9f85a1"),
    "Rollno" : 5,
    "name" : "saurabh",
    "subject" : "TOC",
    "marks" : 78
}

//USING ENSURE INDEX
> db.student.ensureIndex({Rollno:1});
{ "numIndexesBefore" : 3, "note" : "all indexes already exist", "ok" : 1 }

//USING GET INDEX:
> db.student.getIndexes();
[
    {
        "v" : 1,
        "key" : {
            "_id" : 1
        },
        "name" : "_id_",
        "ns" : "mydb.student"
    },
    {
        "v" : 1,
        "key" : {
            "marks" : 1
        },
        "name" : "marks_1",
        "ns" : "mydb.student"
    },
    {
        "v" : 1,
        "key" : {
            "Rollno" : 1
        },
        "name" : "Rollno_1",
        "ns" : "mydb.student"
    }

// USING MINIMUM INDEX:
> db.student.find().min({Rollno:4});
{ "_id" : ObjectId("541c0e05a8dc3dd4fa9f859e"), "Rollno" : 4, "name" : "snehal", "subject" : "TOC", "marks" : 81 }
{ "_id" : ObjectId("541c0e05a8dc3dd4fa9f859f"), "Rollno" : 5, "name" : "saurabh", "subject" : "TOC", "marks" : 78 }

//USING MAXIMUM INDEX:
> db.student.find().max({Rollno:2});
{ "_id" : ObjectId("541c0cf4a8dc3dd4fa9f859b"), "Rollno" : 1, "name" : "nikita", "subject" : "DMSA", "marks" : 78 }

//USING MINIMUM INDEX:
> db.student.find().max({Rollno:3});
{ "_id" : ObjectId("541c0cf4a8dc3dd4fa9f859b"), "Rollno" : 1, "name" : "nikita", "subject" : "DMSA", "marks" : 78 }
{ "_id" : ObjectId("541c0d92a8dc3dd4fa9f859c"), "Rollno" : 2, "name" : "kiran", "subject" : "OSD", "marks" : 75 }

//USING MINIMUM INDEX:
> db.student.find().min({Rollno:2});
{ "_id" : ObjectId("541c0d92a8dc3dd4fa9f859c"), "Rollno" : 2, "name" : "kiran", "subject" : "OSD", "marks" : 75 }
{ "_id" : ObjectId("541c0ddca8dc3dd4fa9f859d"), "Rollno" : 3, "name" : "komal", "subject" : "TOC", "marks" : 69 }
{ "_id" : ObjectId("541c0e05a8dc3dd4fa9f859e"), "Rollno" : 4, "name" : "snehal", "subject" : "TOC", "marks" : 81 }
{ "_id" : ObjectId("541c0e05a8dc3dd4fa9f859f"), "Rollno" : 5, "name" : "saurabh", "subject" : "TOC", "marks" : 78 }


//SORT INDEX IN ASCENDING
 > db.student.find().sort({Rollno:1}).pretty();
{
    "_id" : ObjectId("541c0cf4a8dc3dd4fa9f859b"),
    "Rollno" : 1,
    "name" : "nikita",
    "subject" : "DMSA",
    "marks" : 78
}
{
    "_id" : ObjectId("541c0d92a8dc3dd4fa9f859c"),
    "Rollno" : 2,
    "name" : "kiran",
    "subject" : "OSD",
    "marks" : 75
}
{
    "_id" : ObjectId("541c0ddca8dc3dd4fa9f859d"),
    "Rollno" : 3,
    "name" : "komal",
    "subject" : "TOC",
    "marks" : 69
}
{
    "_id" : ObjectId("541c0e05a8dc3dd4fa9f859e"),
    "Rollno" : 4,
    "name" : "snehal",
    "subject" : "TOC",
    "marks" : 81
}

{
    "_id" : ObjectId("541c0e2ca8dc3dd4fa9f85a1"),
    "Rollno" : 5,
    "name" : "saurabh",
    "subject" : "TOC",
    "marks" : 78
}

//SORTING IN DESCENDING
> db.student.find().sort({Rollno:-1}).pretty();

{
    "_id" : ObjectId("541c0e05a8dc3dd4fa9f859f"),
    "Rollno" : 5,
    "name" : "saurabh",
    "subject" : "TOC",
    "marks" : 78
}
{
    "_id" : ObjectId("541c0e2ca8dc3dd4fa9f85a0"),
    "Rollno" : 4,
    "name" : "snehal",
    "subject" : "TOC",
    "marks" : 81
}
{
    "_id" : ObjectId("541c0ddca8dc3dd4fa9f859d"),
    "Rollno" : 3,
    "name" : "komal",
    "subject" : "TOC",
    "marks" : 69
}
{
    "_id" : ObjectId("541c0d92a8dc3dd4fa9f859c"),
    "Rollno" : 2,
    "name" : "kiran",
    "subject" : "OSD",
    "marks" : 75
}
{
    "_id" : ObjectId("541c0cf4a8dc3dd4fa9f859b"),
    "Rollno" : 1,
    "name" : "nikita",
    "subject" : "DMSA",
    "marks" : 78
}
//ENSURE INDEX:
> db.student.ensureIndex({Rollno:-1});
{
    "createdCollectionAutomatically" : false,
    "numIndexesBefore" : 3,
    "numIndexesAfter" : 4,
    "ok" : 1
}
> db.student.ensureIndex({Rollno:1});
{ "numIndexesBefore" : 4, "note" : "all indexes already exist", "ok" : 1 }


//GET SIZE OF INDEX:
> db.student.stats();
{
    "ns" : "mydb.student",
    "count" : 7,
    "size" : 784,
    "avgObjSize" : 112,
    "storageSize" : 8192,
    "numExtents" : 1,
    "nindexes" : 4,
    "lastExtentSize" : 8192,
    "paddingFactor" : 1,
    "systemFlags" : 1,
    "userFlags" : 1,
    "totalIndexSize" : 32704,
    "indexSizes" : {
        "_id_" : 8176,
        "marks_1" : 8176,
        "Rollno_1" : 8176,
        "Rollno_-1" : 8176
    },
    "ok" : 1
}

//EXPLAIN:
> db.student.find().explain();
{
    "cursor" : "BasicCursor",
    "isMultiKey" : false,
    "n" : 7,
    "nscannedObjects" : 7,
    "nscanned" : 7,
    "nscannedObjectsAllPlans" : 7,
    "nscannedAllPlans" : 7,
    "scanAndOrder" : false,
    "indexOnly" : false,
    "nYields" : 0,
    "nChunkSkips" : 0,
    "millis" : 0,
    "server" : "gescoe:27017",
    "filterSet" : false
}


//DROP INDEX:
> db.student.dropIndex({Rollno:1});
{ "nIndexesWas" : 4, "ok" : 1 }




===============================

Practical: B mongodbjava

===============================



#===========================================================================================
ASSIGNMENT NO:
TITLE:Connectivity with MongoDB using any Java application.
ROLL NO:73
BATCH:T4
#===========================================================================================
import com.mongodb.MongoClient;
import com.mongodb.MongoException;
import com.mongodb.WriteConcern;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.DBCursor;
import com.mongodb.ServerAddress;
import java.util.Arrays;

public class pr3{
   public static void main( String args[] ){
      try{  
     // To connect to mongodb server
         MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
         // Now connect to your databases
         DB db = mongoClient.getDB( "test" );
     System.out.println("Connect to database successfully");
    
    DBCollection coll = db.getCollection("TE");
         System.out.println("Collection TE selected successfully");
         BasicDBObject doc = new BasicDBObject("Name", "Navin").
            append("Subject", "database").
            append("Marks", 100).
            append("by", "Computer dept");
         coll.insert(doc);
         System.out.println("Document inserted successfully");
      }catch(Exception e){
         System.err.println( e.getClass().getName() + ": " + e.getMessage() );
      }
   }
}
_________________________________________________________________________
OUTPUT
_________________________________________________________________________
root@gescoe:/home/gescoe/Desktop/tecomp20# javac pr3.java
root@gescoe:/home/gescoe/Desktop/tecomp20# java pr3
Connect to database successfully
Collection TE selected successfully
Document inserted successfully
root@gescoe:/home/gescoe/Desktop/tecomp20# mongo
MongoDB shell version: 2.6.4
connecting to: test
> use test
switched to db test
> show collections
TE
records
system.indexes
> db.TE.find().pretty()
{
    "_id" : ObjectId("54226147e4b05ff6093bdf03"),
    "Name" : "Navin",
    "Subject" : "Waghwani",
    "Marks" : 100,
    "by" : "tutorials point"
}
> exit
bye
_______________________________________________________________________

 

No comments:

Post a Comment