assignme · oracle/mysql(odbc/jdbc), sql prompt to create data base tables insert, update data...

42
***************************************************************** Assignment : Group A-1 Problem Definition : DBMS using connection(client data server, two tier) Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate use of stored procedures / functions( create procedure at the data side and make use f it on client side) Title: Basic Database Queries Name : Bora Mayur Rajendra Roll No : 12 Batch : T1 Performed On : 08 August 2016,Tuesday ***************************************************************** Java Code: import java.sql.*; public class MysqlProc1 { public static void main(String[] args) { try{ Class.forName("com.mysql.jdbc.Driver"); Connection c=DriverManager.getConnection("jdbc:mysql://localhost:3306/t1","root","") ; CallableStatement cs=c.prepareCall("{call p1(?,?)}"); cs.setInt(1,4); cs.registerOutParameter(2, java.sql.Types.VARCHAR); cs.executeUpdate(); System.out.print(cs.getString(2)); } catch(Exception e) { System.out.println(e); } } } ***************************************************************** MySQL Part: gurukul@ubuntu:~$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 40 Server version: 5.5.37-0ubuntu0.12.10.1 (Ubuntu)

Upload: others

Post on 18-Aug-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

*****************************************************************

Assignment : Group A-1

Problem Definition : DBMS using connection(client data server, two tier)

Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert,

update data values, delete table, use table, select queries with/without

where clauses. demonstrate use of stored procedures / functions( create

procedure at the data side and make use f it on client side)

Title: Basic Database Queries

Name : Bora Mayur Rajendra

Roll No : 12

Batch : T1

Performed On : 08 August 2016,Tuesday

*****************************************************************

Java Code:

import java.sql.*;

public class MysqlProc1 {

public static void main(String[] args) {

try{

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

Connection

c=DriverManager.getConnection("jdbc:mysql://localhost:3306/t1","root","")

;

CallableStatement cs=c.prepareCall("{call p1(?,?)}");

cs.setInt(1,4);

cs.registerOutParameter(2, java.sql.Types.VARCHAR);

cs.executeUpdate();

System.out.print(cs.getString(2));

}

catch(Exception e)

{

System.out.println(e);

}

}

}

*****************************************************************

MySQL Part:

gurukul@ubuntu:~$ mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 40

Server version: 5.5.37-0ubuntu0.12.10.1 (Ubuntu)

Page 2: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

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> create database class

-> ;

Query OK, 1 row affected (0.00 sec)

mysql> use class

Database changed

mysql> create table st1(rno int(3),name varchar(30));

Query OK, 0 rows affected (0.02 sec)

mysql> desc st1

-> ;

+-------+-------------+------+-----+---------+-------+

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

+-------+-------------+------+-----+---------+-------+

| rno | int(3) | YES | | NULL | |

| name | varchar(30) | YES | | NULL | |

+-------+-------------+------+-----+---------+-------+

2 rows in set (0.00 sec)

mysql> alter table st1 add address varchar(30);

Query OK, 0 rows affected (0.01 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> desc st1;

+---------+-------------+------+-----+---------+-------+

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

+---------+-------------+------+-----+---------+-------+

| rno | int(3) | YES | | NULL | |

| name | varchar(30) | YES | | NULL | |

| address | varchar(30) | YES | | NULL | |

+---------+-------------+------+-----+---------+-------+

3 rows in set (0.00 sec)

mysql> alter table st1 modify address varchar(35);

Query OK, 0 rows affected (0.01 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> desc st1;'

+---------+-------------+------+-----+---------+-------+

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

+---------+-------------+------+-----+---------+-------+

| rno | int(3) | YES | | NULL | |

| name | varchar(30) | YES | | NULL | |

Page 3: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

| address | varchar(35) | YES | | NULL | |

+---------+-------------+------+-----+---------+-------+

3 rows in set (0.00 sec)

mysql> alter table st1 add constraint p1 primary key(rno);

Query OK, 0 rows affected (0.01 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> desc st1

-> ;

+---------+-------------+------+-----+---------+-------+

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

+---------+-------------+------+-----+---------+-------+

| rno | int(3) | NO | PRI | 0 | |

| name | varchar(30) | YES | | NULL | |

| address | varchar(35) | YES | | NULL | |

+---------+-------------+------+-----+---------+-------+

3 rows in set (0.00 sec)

mysql> insert into st1 values(1,"bhagyashri",'chandwad');

Query OK, 1 row affected (0.03 sec)

mysql> insert into st1 values(2,"anjali",'pune');

Query OK, 1 row affected (0.02 sec)

mysql> insert into st1 (rno,name)values(3,"Dipali");

Query OK, 1 row affected (0.00 sec)

mysql> select * from st1;

+-----+------------+----------+

| rno | name | address |

+-----+------------+----------+

| 1 | bhagyashri | chandwad |

| 2 | anjali | pune |

| 3 | Dipali | NULL |

+-----+------------+----------+

3 rows in set (0.00 sec)

mysql> delete from st1 where rno=3;

Query OK, 1 row affected (0.03 sec)

mysql> select * from st1;

+-----+------------+----------+

| rno | name | address |

+-----+------------+----------+

| 1 | bhagyashri | chandwad |

| 2 | anjali | pune |

+-----+------------+----------+

2 rows in set (0.00 sec)

mysql> insert into st1 values(3,"Dipali",'pune');

Query OK, 1 row affected (0.01 sec)

Page 4: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

mysql> insert into st1 values(4,"sayali",'chandwad');

Query OK, 1 row affected (0.00 sec)

mysql> insert into st1 values(5,"jyoti",'nasik');

Query OK, 1 row affected (0.01 sec)

mysql> insert into st1 values(6,"komal",'mumbai');

Query OK, 1 row affected (0.00 sec)

mysql> select * from st1;

+-----+------------+----------+

| rno | name | address |

+-----+------------+----------+

| 1 | bhagyashri | chandwad |

| 2 | anjali | pune |

| 3 | Dipali | pune |

| 4 | sayali | chandwad |

| 5 | jyoti | nasik |

| 6 | komal | mumbai |

+-----+------------+----------+

6 rows in set (0.00 sec)

mysql> insert into st1 values(8,"komal",'chalisgaon');

Query OK, 1 row affected (0.01 sec)

mysql> delete from st1 where address='chalisgaon'

-> ;

Query OK, 1 row affected (0.00 sec)

mysql> select * from st1;

+-----+------------+----------+

| rno | name | address |

+-----+------------+----------+

| 1 | bhagyashri | chandwad |

| 2 | anjali | pune |

| 3 | Dipali | pune |

| 4 | sayali | chandwad |

| 5 | jyoti | nasik |

| 6 | komal | mumbai |

+-----+------------+----------+

6 rows in set (0.00 sec)

mysql> select * from st1 order by name desc;

+-----+------------+----------+

| rno | name | address |

+-----+------------+----------+

| 4 | sayali | chandwad |

| 6 | komal | mumbai |

| 5 | jyoti | nasik |

| 3 | Dipali | pune |

| 1 | bhagyashri | chandwad |

| 2 | anjali | pune |

+-----+------------+----------+

Page 5: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

6 rows in set (0.02 sec)

mysql> select * from st1 order by name;

+-----+------------+----------+

| rno | name | address |

+-----+------------+----------+

| 2 | anjali | pune |

| 1 | bhagyashri | chandwad |

| 3 | Dipali | pune |

| 5 | jyoti | nasik |

| 6 | komal | mumbai |

| 4 | sayali | chandwad |

+-----+------------+----------+

6 rows in set (0.00 sec)

mysql> insert into st1 values(7,"reshma",'yeola');

Query OK, 1 row affected (0.00 sec)

mysql> select distinct (address) from st1 order by name;

+----------+

| address |

+----------+

| pune |

| chandwad |

| nasik |

| mumbai |

| yeola |

+----------+

5 rows in set (0.00 sec)

mysql> select distinct (address) from st1;

+----------+

| address |

+----------+

| chandwad |

| pune |

| nasik |

| mumbai |

| yeola |

+----------+

5 rows in set (0.00 sec)

mysql> select * from st1;

+-----+------------+----------+

| rno | name | address |

+-----+------------+----------+

| 1 | bhagyashri | chandwad |

| 2 | anjali | pune |

| 3 | Dipali | pune |

| 4 | sayali | chandwad |

| 5 | jyoti | nasik |

| 6 | komal | mumbai |

| 7 | reshma | yeola |

+-----+------------+----------+

Page 6: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

7 rows in set (0.00 sec)

mysql> select * from st1 where address="chandwad" or address ="pune"

-> ;

+-----+------------+----------+

| rno | name | address |

+-----+------------+----------+

| 1 | bhagyashri | chandwad |

| 2 | anjali | pune |

| 3 | Dipali | pune |

| 4 | sayali | chandwad |

+-----+------------+----------+

4 rows in set (0.00 sec)

mysql> select * from st1 where address="c%"

-> ;

Empty set (0.00 sec)

mysql> select * from st1 where address like "c%"

-> ;

+-----+------------+----------+

| rno | name | address |

+-----+------------+----------+

| 1 | bhagyashri | chandwad |

| 4 | sayali | chandwad |

+-----+------------+----------+

2 rows in set (0.00 sec)

mysql> create table stud_marks (rno int,marks int);

Query OK, 0 rows affected (0.01 sec)

mysql> alter table stud_marks add foreign key(rno) references st1(rno);

Query OK, 0 rows affected (0.04 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> select * from stud_marks;

Empty set (0.00 sec)

mysql> insert into stud_marks values(3,80);

Query OK, 1 row affected (0.00 sec)

mysql> select * from stud_marks;

+------+-------+

| rno | marks |

+------+-------+

| 3 | 80 |

+------+-------+

1 row in set (0.00 sec)

mysql> select rno,name,marks from stud_marks,st1;

ERROR 1052 (23000): Column 'rno' in field list is ambiguous

mysql> select st1.rno,name,marks from stud_marks,st1;

+-----+------------+-------+

| rno | name | marks |

Page 7: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

+-----+------------+-------+

| 1 | bhagyashri | 80 |

| 2 | anjali | 80 |

| 3 | Dipali | 80 |

| 4 | sayali | 80 |

| 5 | jyoti | 80 |

| 6 | komal | 80 |

| 7 | reshma | 80 |

+-----+------------+-------+

7 rows in set (0.00 sec)

mysql> select st1.rno,name,marks from st1,stud_marks;

+-----+------------+-------+

| rno | name | marks |

+-----+------------+-------+

| 1 | bhagyashri | 80 |

| 2 | anjali | 80 |

| 3 | Dipali | 80 |

| 4 | sayali | 80 |

| 5 | jyoti | 80 |

| 6 | komal | 80 |

| 7 | reshma | 80 |

+-----+------------+-------+

7 rows in set (0.00 sec)

mysql> select st1.rno,name,marks from st1,stud_marks where

st1.rno=stud_marks.rno;

+-----+--------+-------+

| rno | name | marks |

+-----+--------+-------+

| 3 | Dipali | 80 |

+-----+--------+-------+

1 row in set (0.00 sec)

mysql> delimiter $

mysql> create procedure p1 (IN rno1 int(3),OUT name1 varchar(20)) begin

select name into name1 from st1 where rno=rno1;

-> end;

-> $

Query OK, 0 rows affected (0.03 sec)

mysql> call p1(1,@name1)$

Query OK, 1 row affected (0.01 sec)

mysql> select @name1 $

+------------+

| @name1 |

+------------+

| bhagyashri |

+------------+

1 row in set (0.00 sec)

mysql> delimiter $

Page 8: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

mysql> create procedure p1 (IN rno1 int(3),OUT name1 varchar(20)) begin

select name into name1 from st1 where rno=rno1; end;$

Query OK, 0 rows affected (0.00 sec)

mysql> call p1(1,@name1)$

Query OK, 1 row affected (0.00 sec)

mysql> select @name1 $

+--------+

| @name1 |

+--------+

| anjali |

+--------+

1 row in set (0.00 sec)

mysql>

*****************************************************************

Page 9: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

*****************************************************************

Assignment : Group A-2

Problem Definition : DBMS using connection(client application server-data

server, three tier) Oracle/MYSQL(ODBC/JDBC), SQL joins, prompt.

Title: SQL joins in MySQL using 3-tier

Name : Bora Mayur Rajendra

Roll No : 12

Batch : T1

Performed On :

*****************************************************************

JSP Code:

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<%@ page import="java.sql.*" %>

<form>

<input type="radio" name="join" value="select stud_info.Rno,Name,Marks

from stud_info,stud_Marks where stud_info.Rno=stud_Marks.Rno"/>Display

Natural Join

<br>

<input type="radio" name="join" value="select stud_info.Rno,Name,Marks

from stud_info left join stud_Marks on

stud_info.Rno=stud_Marks.Rno"/>Display Left Join

<br>

<input type="radio" name="join" value="select

stud_Marks.Rno,Name,Marks from stud_info right join stud_Marks on

stud_info.Rno = stud_Marks.Rno"/>Display Right Join

<br>

<input type=submit value=submit>

<br>

<%

String sql=request.getParameter("join");

try

{

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

Connection

c=DriverManager.getConnection("jdbc:mysql://localhost:3306/mayur","root",

"");

Statement st= c.createStatement();

out.println("stud_info");

out.println("<table border=1

align=center><tr>");

out.println("<th>Roll No</th>");

out.println("<th>Name</th>");

out.println("<tr>");

ResultSet rs1=st.executeQuery("select * from

stud_info");

Page 10: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

while(rs1.next())

{

out.println("<tr>");

out.println("<td>"+rs1.getInt(1)+"</td>");

out.println("<td>"+rs1.getString(2)+"</td>");

out.println("</tr>");

}

out.println("</table>");

out.println("stud_Marks");

out.println("<table border=1 align=center><tr>");

out.println("<th>Roll No</th>");

out.println("<th>Marks</th>");

out.println("</tr>");

ResultSet rs2=st.executeQuery("select * from

stud_Marks");

while(rs2.next())

{

out.println("<tr>");

out.println("<td>"+rs2.getInt(1)+"</td>");

out.println("<td>"+rs2.getInt(2)+"</td>");

out.println("</tr>");

}

out.println("</table>");

out.println(sql);

out.println("<br>");

out.println("<b> Join Output</b>");

out.println("<table border=1 align=center><tr>");

out.println("<th>Roll No</th>");

out.println("<th>Name</th>");

out.println("<th>Marks</th>");

out.println("</tr>");

ResultSet rs3=st.executeQuery(sql);

while(rs3.next())

{

out.println("<tr>");

out.println("<td>"+rs3.getInt(1)+"</td>");

out.println("<td>"+rs3.getString(2)+"</td>");

out.println("<td>"+rs3.getInt(3)+"</td>");

out.println("</tr>");

}

out.println("</table>");

}

catch(Exception e)

{

out.println(e);

}

%>

Page 11: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

</form>

*****************************************************************

Output:

1) Display Natural Join

Display Left Join

Display Right Join

stud_info

Roll No Name

1 mayur

2 Rachana

3 snehal

4 ganesh

5 nitin

8 xyz

9 pqr

stud_Marks

Roll No Marks

1 80

2 90

3 70

4 60

5 90

6 90

7 90

select stud_info.Rno,Name,Marks from stud_info,stud_Marks where

stud_info.Rno=stud_Marks.Rno

Join Output

Roll No Name Marks

1 mayur 80

2 Rachana 90

3 snehal 70

4 ganesh 60

5 nitin 90

Display Natural Join

2) Display Left Join

Display Right Join

stud_info

Roll No Name

1 mayur

2 Rachana

3 snehal

4 ganesh

5 nitin

8 xyz

9 pqr

stud_Marks

Roll No Marks

Page 12: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

1 80

2 90

3 70

4 60

5 90

6 90

7 90

select stud_info.Rno,Name,Marks from stud_info left join stud_Marks on

stud_info.Rno=stud_Marks.Rno

Join Output

Roll No Name Marks

1 mayur 80

2 Rachana 90

3 snehal 70

4 ganesh 60

5 nitin 90

8 xyz 0

9 pqr 0

Display Natural Join

Display Left Join

Display Right Join

stud_info

Roll No Name

1 mayur

2 Rachana

3 snehal

4 ganesh

5 nitin

8 xyz

9 pqr

stud_Marks

Roll No Marks

1 80

2 90

3 70

4 60

5 90

6 90

7 90

select stud_Marks.Rno,Name,Marks from stud_info right join stud_Marks on

stud_info.Rno = stud_Marks.Rno

Join Output

Roll No Name Marks

1 mayur 80

2 Rachana 90

3 snehal 70

4 ganesh 60

5 nitin 90

6 null 90

7 null 90

*****************************************************************

Page 13: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

**************************************************************

Assignment : Group A-3

Problem Definition :Design and Develop SQL DDL Statement which

demonstrate the use of SQL objects such as Tble, View and Index using

Client Data Server( two tier)

Title: SQL DDL operation on Table, View and Index

Name : Bora Mayur Rajendra

Roll No : 12

Batch : T1

Performed On :

**************************************************************

Java Code:

package ga3;

import java.sql.*;

import java.util.*;

public class GA3 {

static public Scanner s = new Scanner(System.in);

static public Connection c;

static public Statement st;

static public ResultSet rs;

static public String qry;

public static void main(String[] args)

{

try

{

int ch;

do{

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

c=DriverManager.getConnection("jdbc:mysql://localhost:3306/dbga3","

root","");

st=c.createStatement();

System.out.print("Enter your choice :\n\t 1)Table

\n\t 2) View \n\t 3 Index \n");

ch=s.nextInt();

switch(ch)

{

case 1:Tablef();

break;

case 2:Viewf();

break;

case 3:Indexf();

break;

Page 14: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

}

}while(ch<4);

}

catch(Exception e)

{

System.out.print(e);

}

}//main() complete

public static void Tablef()

{

try

{

int ch;

do{

System.out.print("\n Enter your choice :\n\t 1)

create \n\t 2) Desc \n\t 3 Alter \n\t 4) Drop \n");

ch=s.nextInt();

switch(ch)

{

case 1:qry="Create table stud(rno int(3),name

varchar(20))";

st.executeUpdate(qry);

System.out.print("Table stud created

Successfully");

break;

case 2:qry="desc stud";

rs=st.executeQuery(qry);

System.out.print("Table stud Details");

while(rs.next())

{

System.out.print("\nField name :

"+rs.getString(1));

System.out.print("\nData Type :

"+rs.getString(2));

}

break;

case 3:

qry="Alter table stud add salary int(5)";

st.executeUpdate(qry);

System.out.print("table is Alter,new column

marks is added");

break;

case 4:

qry="Drop table stud";

st.executeUpdate(qry);

System.out.println("Table is drop");

break;

} //switch case complete

Page 15: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

}while(ch<5);

}//try complete

catch(Exception e)

{

System.out.print(e);

}

}

public static void Viewf()

{

try

{

int ch;

do{

System.out.print("\n Enter your choice :\n\t 1)

create \n\t 2) Desc \n\t 3) Drop \n");

ch=s.nextInt();

switch(ch)

{

case 1:

qry="create view v1 as select rno,name from stud";

st.executeUpdate(qry);

System.out.print("view on Table stud created

Successfully");

break;

case 2:qry="desc v1";

rs=st.executeQuery(qry);

System.out.print("View v1 on table stud Details");

while(rs.next())

{

System.out.print("\nField name :

"+rs.getString(1));

System.out.print("\nData Type :

"+rs.getString(2));

}

break;

case 3:

qry="drop view v1";

st.executeUpdate(qry);

System.out.print("View is dropped");

break;

} //switch case complete

}while(ch<4);

}//try complete

catch(Exception e)

{

System.out.print(e);

Page 16: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

}

}

public static void Indexf()

{

try

{

int ch;

do{

System.out.print("\n Enter your choice :\n\t 1)

create \n\t 2) show \n\t 3) Drop \n");

ch=s.nextInt();

switch(ch)

{

case 1:

qry="alter table stud add index stud_index(name)";

st.executeUpdate(qry);

System.out.print("Index is created...");

break;

case 2:qry="show index from stud";

rs=st.executeQuery(qry);

while(rs.next())

{

System.out.print("\nIndex Name :

"+rs.getString(3));

System.out.print("\nField :

"+rs.getString(5));

System.out.print("\nIndex Type :

"+rs.getString(11));

}

break;

case 3:

qry="alter table emp drop index stud_index";

st.executeUpdate(qry);

System.out.print("Index is dropped...");

break;

} //switch case complete

}while(ch<4);

}//try complete

catch(Exception e)

{

System.out.print(e);

}

}

}//class complete

Page 17: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

**************************************************************

Output:

Enter your choice :

1)Table

2) View

3 Index

1

Enter your choice :

1) create

2) Desc

3 Alter

4) Drop

1

Table stud created Successfully

Enter your choice :

1) create

2) Desc

3 Alter

4) Drop

2

Table stud Details

Field name : rno

Data Type : int(3)

Field name : name

Data Type : varchar(20)

Enter your choice :

1) create

2) Desc

3 Alter

4) Drop

3

table is Alter,new column marks is added

Enter your choice :

1) create

2) Desc

3 Alter

4) Drop

5

Enter your choice :

1)Table

2) View

3 Index

2

Enter your choice :

1) create

2) Desc

3) Drop

1

view on Table stud created Successfully

Page 18: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

Enter your choice :

1) create

2) Desc

3) Drop

2

View v1 on table stud Details

Field name : rno

Data Type : int(3)

Field name : name

Data Type : varchar(20)

Enter your choice :

1) create

2) Desc

3) Drop

4

Enter your choice :

1)Table

2) View

3 Index

3

Enter your choice :

1) create

2) show

3) Drop

1

Index is created...

Enter your choice :

1) create

2) show

3) Drop

2

Index Name : stud_index

Field : name

Index Type : BTREE

Enter your choice :

1) create

2) show

3) Drop

**************************************************************

Page 19: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

# ---------------------------------------------------------------#

Assignment : Group A-4

# Problem Definition : Write a program in python to read and display the

inode information for a given text file, image file.

# Title: read and display inode information of file

# Name : Bora Mayur Rajendra

# Roll No : 12

# Batch : T1

# Performed On : 21 June 2016, Tuesday

#----------------------------------------------------------------

# Text File :

# Code:

import os,time

from stat import *

info= os.stat("a4.py")

print "File info",info

print "Inode No:",info[ST_INO]

print "User Id: ",info[ST_UID]

print "Group Id: ",info[ST_GID]

print "Number Of Hard Links: ",info[ST_NLINK]

print "Device Id: ",info.st_rdev

print "Total size in Bytes: ",info[ST_SIZE]

print "Block size for file system IO: ",info.st_blksize

print "Number of 512 Bytes allocated: ",info.st_blocks

print "Time of last inode access:

",time.asctime(time.localtime(info[ST_ATIME]))

print "Time of last inode change:

",time.asctime(time.localtime(info[ST_CTIME]))

print "Time of last inode modification:

",time.asctime(time.localtime(info[ST_MTIME]))

#----------------------------------------------------------------

# Output:

# gurukul@ubuntu:~$ cd /home/gurukul/mayur

# gurukul@ubuntu:~/mayur$ python a4.py

# File info posix.stat_result(st_mode=33204, st_ino=181L, st_dev=1794L,

st_nlink=1, st_uid=1000, st_gid=1000, st_size=1257L, st_atime=1466518180,

st_mtime=1466518178, st_ctime=1466518178)

# Inode No: 181

# User Id: 1000

# Group Id: 1000

# Number Of Hard Links: 1

# Device Id: 0

# Total size in Bytes: 1257

# Block size for file system IO: 4096

# Number of 512 Bytes allocated: 8

# Time of last inode access: Tue Jun 21 10:38:40 2016

Page 20: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

# Time of last inode change: Tue Jun 21 10:38:29 2016

# Time of last inode modification: Tue Jun 21 10:38:29 2016

# gurukul@ubuntu:~/mayur$

#----------------------------------------------------------------

# Image File :

# Code:

import os,time

from stat import *

info= os.stat("image.jpeg")

print "File info",info

print "Inode No:",info[ST_INO]

print "User Id: ",info[ST_UID]

print "Group Id: ",info[ST_GID]

print "Number Of Hard Links: ",info[ST_NLINK]

print "Device Id: ",info.st_rdev

print "Total size in Bytes: ",info[ST_SIZE]

print "Block size for file system IO: ",info.st_blksize

print "Number of 512 Bytes allocated: ",info.st_blocks

print "Time of last inode access:

",time.asctime(time.localtime(info[ST_ATIME]))

print "Time of last inode change:

",time.asctime(time.localtime(info[ST_CTIME]))

print "Time of last inode modification:

",time.asctime(time.localtime(info[ST_MTIME]))

#----------------------------------------------------------------

# Output:

# gurukul@ubuntu:~$ cd /home/gurukul/mayur

# gurukul@ubuntu:~/mayur$ python a4.py

# File info posix.stat_result(st_mode=33204, st_ino=1137L, st_dev=1794L,

st_nlink=1, st_uid=1000, st_gid=1000, st_size=7127L, st_atime=1466520259,

st_mtime=1466520250, st_ctime=1466520250)

# Inode No: 1137

# User Id: 1000

# Group Id: 1000

# Number Of Hard Links: 1

# Device Id: 0

# Total size in Bytes: 7127

# Block size for file system IO: 4096

# Number of 512 Bytes allocated: 16

# Time of last inode access: Tue Jun 21 10:44:19 2016

# Time of last inode change: Tue Jun 21 10:44:10 2016

# Time of last inode modification: Tue Jun 21 10:44:10 2016

# gurukul@ubuntu:~/mayur$

#----------------------------------------------------------------

Page 21: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

# ---------------------------------------------------------------

# Assignment : Group A-5

# Problem Definition : 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++.

# Title: IPC

# Name : Bora Mayur Rajendra

# Roll No : 12

# Batch : T1

# Performed On : 27 June 2016, Monday

#----------------------------------------------------------------

# Code:

import os,sys

print "Process A accepts the String"

print "Process B inverse the String"

# File descriptor r,w for reading and writing

r,w=os.pipe()

processid=os.fork()

if processid:

# This is process B

os.close(w)

r=os.fdopen(r)

print " Process B is reading..."

str=r.read()

print " String from process A is:",str

rev_str=str[ : : -1]

print "Reverse string is:",rev_str

sys.exit(0)

else:

# This is process A

os.close(r)

w=os.fdopen(w,'w')

print "Process A is running"

str1=raw_input("Enter String")

w.write(str1)

w.close()

#----------------------------------------------------------------

# Output:

#gurukul@ubuntu:~$ cd mayur

#gurukul@ubuntu:~/mayur$ python a5.py

#Process A accepts the String

#Process B inverse the String

# Process B is reading...

Page 22: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

#Process A is running

#Enter String Mansion

# String from process A is: Mansion

#Reverse string is: noisnaM

#gurukul@ubuntu:~/mayur$

#----------------------------------------------------------------

Page 23: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

#-----------------------------------------------------------

# Assignment : Group A-6

# Problem Definition : Use Python for Socket Programming to connect two

or more PCs to share a text file.

# Title: Simple Socket Program

# Name : Bora Mayur Rajendra

# Roll No : 12

# Batch : T1

# Performed On : 3 July 2016, Monday

#-----------------------------------------------------------

# Code for simple socket program for server side

# Simple Socket Program - Server side ( same PC - Localhost - 127.0.0.1 )

import socket # import socket package

s=socket.socket() # use socket function to create socket

on server side

s.bind(("",12012)) # server bind dynamically to

another port

s.listen(2) # number of request client can approach

to server

while 1: # if true

c,addr=s.accept() # client address sends and server

accepts the ip address and port number

print 'Got Connection From',addr # display the sg got connection

from adn the ip address and port number

c.send('Hi this is Server') # server send msg that "Hi this

is server"

print c.recv(1024) # receives the msg in buffer size

1024 bytes

c.close() # close client socket

s.close() # close server socket

#-----------------------------------------------------------

# Code for simple socket program for client side

import socket # import socket package

c=socket.socket() # use socket function to create socket

on server side

c.connect(("",12012)) # client connect to server

print c.recv(1024) # receives the msg in buffer size

1024 bytes

c.send('Hello this is Client') # client send msg that

"Hello this is client"

c.close() # close client socket

#-----------------------------------------------------------

# Output for server file:

Page 24: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

# gurukul@ubuntu:~$ cd /home/gurukul/mayur/A6

# gurukul@ubuntu:~/mayur/A6$ python server.py

# Got Connection From ('127.0.0.1', 51707)

# Hello this is Client

#-----------------------------------------------------------

# Output for client file:

# gurukul@ubuntu:~$ cd /home/gurukul/mayur/A6

# gurukul@ubuntu:~/mayur/A6$ python client.py

# Hi this is Server

# gurukul@ubuntu:~/mayur/A6$

#-----------------------------------------------------------

# Code for chatting socket program for server side

import socket

s=socket.socket()

s.bind(("",12013))

s.listen(1)

while 1:

c,addr=s.accept()

print "Got Connection From:"

while 1:

sdata=raw_input("server:")

c.send(sdata)

cdata=c.recv(512)

print "Client : ",cdata

#-----------------------------------------------------------

# Code for chatting socket program for client side

import socket

c=socket.socket()

c.connect(("",12013))

while 1:

sdata=c.recv(512)

print "Server: ",sdata

cdata=raw_input("Client: ")

c.send(cdata)

#-----------------------------------------------------------

# Output for server chatting file:

# gurukul@ubuntu:~$ cd /home/gurukul/mayur/A6

# gurukul@ubuntu:~/mayur/A6$ python schat.py

# Got Connection From:

Page 25: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

# server:hi i m server

# Client : hi i m client

# server:

#-----------------------------------------------------------

# Output for client chatting file:

# gurukul@ubuntu:~$ cd /home/gurukul/mayur/A6

# gurukul@ubuntu:~/mayur/A6$ python cchat.py

# Server: hi i m server

# Client: hi i m client

#-----------------------------------------------------------

# Code for file socket program for server side

import socket

s=socket.socket()

s.bind(("",12014))

s.listen(1)

while 1:

c,addr=s.accept()

print 'Got Connection From',addr

f=open("/home/gurukul/server/vfs.py","r")

data=f.read(5100)

c.send(data)

f.close()

c.close()

#-----------------------------------------------------------

# Code for file socket program for client side

import socket

c=socket.socket()

c.connect(("localhost",12014))

f=open("vfs.py","w")

data=c.recv(5100)

f.write(data)

print "File downloaded successfully"

f.close()

c.close()

#-----------------------------------------------------------

# Output for server file:

# gurukul@ubuntu:~$ cd /home/gurukul/mayur/A6

# gurukul@ubuntu:~/mayur/A6$ python fserver.py

Page 26: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

# Got Connection From ('127.0.0.1', 51121)

#-----------------------------------------------------------

# Output for client file:

# gurukul@ubuntu:~$ cd /home/gurukul/mayur/A6

# gurukul@ubuntu:~/mayur/A6$ python fclient.py

# File downloaded successfully

# gurukul@ubuntu:~/mayur/A6$

#-----------------------------------------------------------

Page 27: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

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

Assignment : Group B-1

Problem Definition : Design at least 10 SQL Queries for suitable databse

application using SQL DML Statements: Insert, Select, Update, Delete

clauses using distinct, count, aggregation on client data server( three

tier )

Title: SQL DML Queries

Name : Bora Mayur Rajendra

Roll No : 12

Batch : T1

Performed On :

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

JSP Part:

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<%@ page import = "java.sql.*" %>

<body>

<form>

<input type= "radio" name ="r1" value="select * from stud;"/> Display all

information about student

<br>

<input type= "radio" name ="r1" value="select roll_no ,name from stud

where address="deola";"/> rollno and name of srudents from deola

<br>

<input type= "radio" name ="r1" value="select name from stud where name

like 's%';"/> name of students starting with s

<br>

<input type="submit" name="r2" value="submit">

<br>

<%

try

{

String sql= request.getParameter("r1");

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

Connection

c=DriverManager.getConnection("jdbc:mysql://localhost:3306/mayur","root",

"");

Statement st= c.createStatement();

ResultSet rs=st.executeQuery(sql);

ResultSetMetaData rsmd=rs.getMetaData();

int numofcol= rsmd.getColumnCount();

Page 28: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

out.println("<table border=1>");

while(rs.next())

{

out.println("<tr>");

for(int i=1;i<=numofcol;i++)

{

out.println("<td>");

int type=rsmd.getColumnType(i);

if(type==Types.VARCHAR)

out.println(rs.getString(i));

else

out.println(rs.getInt(i));

out.println("</td>");

}

out.println("/<tr>");

}

out.println("/<table>");

}

catch(Exception e)

{

}

%>

</form>

</body>

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

MySQL Part:

gurukul@ubuntu:~$ mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 36

Server version: 5.5.37-0ubuntu0.12.10.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> use mayur;

Database changed

Page 29: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

mysql> select * from stud;

+---------+---------+----------+

| roll_no | name | address |

+---------+---------+----------+

| 1 | mayur | loni |

| 2 | Rachana | dhule |

| 3 | neha | deola |

| 4 | snehal | deola |

| 5 | | manmad |

| 6 | sarita | manmad |

| 7 | mrunal | malegaon |

| 8 | gaurav | |

| 9 | anita | NULL |

+---------+---------+----------+

9 rows in set (0.00 sec)

mysql> select roll_no ,name from stud where address="deola";

+---------+--------+

| roll_no | name |

+---------+--------+

| 3 | neha |

| 4 | snehal |

+---------+--------+

2 rows in set (0.00 sec)

mysql> select name from stud where name like 's%';

+--------+

| name |

+--------+

| snehal |

| sarita |

+--------+

2 rows in set (0.01 sec)

Output on Java:

Display all information about student

rollno and name of students from deola

name of students starting with s

/ / / / / / / / / /

1 mayur loni

2 Rachana dhule

3 neha deola

4 snehal deola

5 manmad

6 sarita manmad

7 mrunal malegaon

8 gaurav

9 anita null

Display all information about student

Page 30: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

rollno and name of students from deola

name of students starting with s

/ / /

3 neha

4 snehal

Display all information about student

rollno and name of students from deola

name of students starting with s

/ / /

snehal

sarita

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

Page 31: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

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

Assignment : Group B-2

Problem Definition : Implement database with suitable example using

mongodb and implement all basic operation and

administration command using two tier architecture.

Title: Basic operation on MongoDB

Name : Bora Mayur Rajendra

Roll No : 12

Batch : T1

Performed On : 02 August 2016,Tuesday

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

code and output:

first terminal:

gurukul@ubuntu:~$ cd mongodb-linux-i686-2.4.6/

gurukul@ubuntu:~/mongodb-linux-i686-2.4.6$ cd bin

gurukul@ubuntu:~/mongodb-linux-i686-2.4.6/bin$ ./mongod --dbpath mayur

Mon Sep 12 10:14:38.724

Mon Sep 12 10:14:38.724 warning: 32-bit servers don't have journaling

enabled by default. Please use --journal if you want durability.

Mon Sep 12 10:14:38.724

Mon Sep 12 10:14:38.735 [initandlisten] MongoDB starting : pid=2958

port=27017 dbpath=mayur 32-bit host=ubuntu

Mon Sep 12 10:14:38.735 [initandlisten]

Mon Sep 12 10:14:38.735 [initandlisten] ** NOTE: This is a 32 bit MongoDB

binary.

Mon Sep 12 10:14:38.735 [initandlisten] ** 32 bit builds are

limited to less than 2GB of data (or less with --journal).

Mon Sep 12 10:14:38.735 [initandlisten] ** Note that journaling

defaults to off for 32 bit and is currently off.

Mon Sep 12 10:14:38.735 [initandlisten] ** See

http://dochub.mongodb.org/core/32bit

Mon Sep 12 10:14:38.735 [initandlisten]

Mon Sep 12 10:14:38.735 [initandlisten] db version v2.4.6

Mon Sep 12 10:14:38.735 [initandlisten] git version:

b9925db5eac369d77a3a5f5d98a145eaaacd9673

Mon Sep 12 10:14:38.735 [initandlisten] build info: Linux bs-

linux32.10gen.cc 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008

i686 BOOST_LIB_VERSION=1_49

Mon Sep 12 10:14:38.735 [initandlisten] allocator: system

Mon Sep 12 10:14:38.735 [initandlisten] options: { dbpath: "mayur" }

Mon Sep 12 10:14:38.864 [websvr] admin web console waiting for

connections on port 28017

Mon Sep 12 10:14:38.864 [initandlisten] waiting for connections on port

27017

Mon Sep 12 10:15:12.272 [initandlisten] connection accepted from

127.0.0.1:60762 #1 (1 connection now open)

second terminal:

Page 32: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

gurukul@ubuntu:~/mongodb-linux-i686-2.4.6/bin$ ./mongo

MongoDB shell version: 2.4.6

connecting to: test

Server has startup warnings:

Mon Sep 12 10:14:38.735 [initandlisten]

Mon Sep 12 10:14:38.735 [initandlisten] ** NOTE: This is a 32 bit MongoDB

binary.

Mon Sep 12 10:14:38.735 [initandlisten] ** 32 bit builds are

limited to less than 2GB of data (or less with --journal).

Mon Sep 12 10:14:38.735 [initandlisten] ** Note that journaling

defaults to off for 32 bit and is currently off.

Mon Sep 12 10:14:38.735 [initandlisten] ** See

http://dochub.mongodb.org/core/32bit

Mon Sep 12 10:14:38.735 [initandlisten]

> > use db1

switched to db db1

> db

db1

> db.createCollection("stud")

{ "ok" : 1 }

> db.stud.insert({"name":"mayur"});

> db.stud.find();

{ "_id" : ObjectId("57d6b9166ca8d59f1025a059"), "name" : "mayur" }

> db.stud.insert({"name":"rachana","rno":1});

> db.stud.find();

{ "_id" : ObjectId("57d6b9166ca8d59f1025a059"), "name" : "mayur" }

{ "_id" : ObjectId("57d6b9436ca8d59f1025a05a"), "name" : "rachana", "rno"

: 1 }

> db.stud.insert({"name":"neha","rno":2,"cno":[123,456]});

> db.stud.find();

{ "_id" : ObjectId("57d6b9166ca8d59f1025a059"), "name" : "mayur" }

{ "_id" : ObjectId("57d6b9436ca8d59f1025a05a"), "name" : "rachana", "rno"

: 1 }

{ "_id" : ObjectId("57d6b95f6ca8d59f1025a05b"), "name" : "neha", "rno" :

2, "cno" : [ 123, 456 ] }

> db.createCollection("movie");

{ "ok" : 1 }

>

db.movie.insert({"movie_name":"singham","type":"hindi","budget":50,"produ

cer":{"p1":"prakash","p2":"satyadev"}});

>

db.movie.insert({"movie_name":"singh","type":"hindi","budget":150,"produc

er":{"p1":"mayur","p2":"satyadev"}});

>

db.movie.insert({"movie_name":"john","type":"hindi","budget":150,"produce

r":{"p1":"mayur","p2":"prakash"}});

> db.movie.find();

{ "_id" : ObjectId("57d6ba676ca8d59f1025a05c"), "movie_name" : "players",

"type" : "hindi", "budget" : 100, "producer" : { "p1" : "prakash", "p2" :

"satyadev" } }

{ "_id" : ObjectId("57d6bb146ca8d59f1025a05d"), "movie_name" : "singham",

"type" : "hindi", "budget" : 50, "producer" : { "p1" : "prakash", "p2" :

"satyadev" } }

Page 33: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

{ "_id" : ObjectId("57d6bb2b6ca8d59f1025a05e"), "movie_name" : "singh",

"type" : "hindi", "budget" : 150, "producer" : { "p1" : "mayur", "p2" :

"satyadev" } }

{ "_id" : ObjectId("57d6bb4b6ca8d59f1025a05f"), "movie_name" : "john",

"type" : "hindi", "budget" : 150, "producer" : { "p1" : "mayur", "p2" :

"prakash" }

}db.movie.insert({"movie_name":"players","type":"hindi","budget":100,"pro

ducer":{"p1":"prakash","p2":"satyadev"}});

> db.movie.find();

{ "_id" : ObjectId("57d6ba676ca8d59f1025a05c"), "movie_name" : "players",

"type" : "hindi", "budget" : 100, "producer" : { "p1" : "prakash", "p2" :

"satyadev" } }

> > db.movie.find().pretty();

{

"_id" : ObjectId("57d6ba676ca8d59f1025a05c"),

"movie_name" : "players",

"type" : "hindi",

"budget" : 100,

"producer" : {

"p1" : "prakash",

"p2" : "satyadev"

}

}

{

"_id" : ObjectId("57d6bb146ca8d59f1025a05d"),

"movie_name" : "singham",

"type" : "hindi",

"budget" : 50,

"producer" : {

"p1" : "prakash",

"p2" : "satyadev"

}

}

{

"_id" : ObjectId("57d6bb2b6ca8d59f1025a05e"),

"movie_name" : "singh",

"type" : "hindi",

"budget" : 150,

"producer" : {

"p1" : "mayur",

"p2" : "satyadev"

}

}

{

"_id" : ObjectId("57d6bb4b6ca8d59f1025a05f"),

"movie_name" : "john",

"type" : "hindi",

"budget" : 150,

"producer" : {

"p1" : "mayur",

"p2" : "prakash"

}

}

> db.movie.find({budget:{$gt:50}}).pretty();

Page 34: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

{

"_id" : ObjectId("57d6ba676ca8d59f1025a05c"),

"movie_name" : "players",

"type" : "hindi",

"budget" : 100,

"producer" : {

"p1" : "prakash",

"p2" : "satyadev"

}

}

{

"_id" : ObjectId("57d6bb2b6ca8d59f1025a05e"),

"movie_name" : "singh",

"type" : "hindi",

"budget" : 150,

"producer" : {

"p1" : "mayur",

"p2" : "satyadev"

}

}

{

"_id" : ObjectId("57d6bb4b6ca8d59f1025a05f"),

"movie_name" : "john",

"type" : "hindi",

"budget" : 150,

"producer" : {

"p1" : "mayur",

"p2" : "prakash"

}

}

> db.movie.find({budget:{$gt:50}}).pretty();

{

"_id" : ObjectId("57d6ba676ca8d59f1025a05c"),

"movie_name" : "players",

"type" : "hindi",

"budget" : 100,

"producer" : {

"p1" : "prakash",

"p2" : "satyadev"

}

}

{

"_id" : ObjectId("57d6bb2b6ca8d59f1025a05e"),

"movie_name" : "singh",

"type" : "hindi",

"budget" : 150,

"producer" : {

"p1" : "mayur",

"p2" : "satyadev"

}

}

{

"_id" : ObjectId("57d6bb4b6ca8d59f1025a05f"),

"movie_name" : "john",

Page 35: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

"type" : "hindi",

"budget" : 150,

"producer" : {

"p1" : "mayur",

"p2" : "prakash"

}

}

>

db.movie.find({"producer.p1":"prakash","producer.p2":"satyadev"}).pretty(

);

{

"_id" : ObjectId("57d6ba676ca8d59f1025a05c"),

"movie_name" : "players",

"type" : "hindi",

"budget" : 100,

"producer" : {

"p1" : "prakash",

"p2" : "satyadev"

}

}

{

"_id" : ObjectId("57d6bb146ca8d59f1025a05d"),

"movie_name" : "singham",

"type" : "hindi",

"budget" : 50,

"producer" : {

"p1" : "prakash",

"p2" : "satyadev"

}

}

*****************************************

Page 36: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

# ---------------------------------------------------------------

# Assignment : Group B-5

# Problem Definition : Write a program in Python/C++ to test that

computer is booted with Legacy Boot ROM- BIOS or UEFI.

# Title: Booting with BIOS or UEFI

# Name : Bora Mayur Rajendra

# Roll No : 12

# Batch : T1

# Performed On : 27 June 2016, Monday

#----------------------------------------------------------------

# Code:

import os

if(os.path.exists("/sys/boot/efi")):

print "System is booted with UEFI"

else:

print "System is booted with Legacy BIOS"

#----------------------------------------------------------------

# Output:

#gurukul@ubuntu:~$ cd mayur

#gurukul@ubuntu:~/mayur$ cd B5

#gurukul@ubuntu:~/mayur/B5$ sudo python b5.py

#[sudo] password for gurukul:

#System is booted with Legacy BIOS

#gurukul@ubuntu:~/mayur/B5$

#----------------------------------------------------------------

Page 37: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

# --------------------------------------------------

# Assignment : Group B-11

# Problem Definition : Write a python program for creating virtual file

system on Linux environment.

# Title: create Virtual File System on Linux

# Name : Bora Mayur Rajendra

# Roll No : 12

# Batch : T1

# Performed On : 12 July 2016, Tuesday

#----------------------------------------------------

# Code:

import shelve

filesys=shelve.open('myfilesystem.fs',writeback=True)

current_dir=[]

def install(filesys):

username= raw_input('Enter user name : ')

filesys[""]={"System":{},"Users":{username:{}}}

def current_dictionary():

d=filesys[""]

for element in current_dir:

d=d[element]

return d

def vls(args):

print'Contents of Directory are : ',"/"+"/".join(current_dir)+':'

for i in current_dictionary():

print i

def vcd(args):

if len(args)!=1:

print"Usage : vcd<directory>"

return

if args[0]=="..":

if len(current_dir)==0:

print"Sorry...Can not go above root"

else:

current_dir.pop()

elif args[0] not in current_dictionary():

print"Directory " + agrs[0]+"not found"

else:

current_dir.append(args[0])

def vmkdir(args):

if len(args)!=1:

print "Usage : vmkdir <directory> "

return

d=current_dictionary()[args[0]]={}

Page 38: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

filesys.sync()

COMMANDS={'vls':vls,'vcd':vcd,'vmkdir':vmkdir}

install(filesys)

while True:

raw=raw_input('vfs>')

cmd=raw.split()[0]

if cmd in COMMANDS:

COMMANDS[cmd](raw.split()[1:])

raw_input('Press the Enter key to shutdown the filesystem..')

#----------------------------------------------------

# Output:

#gurukul@ubuntu:~$ cd mayur

#gurukul@ubuntu:~/mayur$ cd B11

#gurukul@ubuntu:~/mayur/B11$ python b11.py

#Enter user name : myfilesystem

#vfs>vls

#Contents of Directory are : /:

#System

#Users

#vfs>vmkdir

#Usage : vmkdir <directory>

#vfs>vmkdir

#Usage : vmkdir <directory>

#vfs>vmkdir TE

#vfs>vls

#Contents of Directory are : /:

#TE

#System

#Users

#vfs>vcd TE

#vfs>vmkdir T1Batch

#vfs>vls

#Contents of Directory are : /TE:

#T1Batch

#vfs>

#----------------------------------------------------

Page 39: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

*****************************************************************

Assignment : Group B-16

Problem Definition : Map reduce operation with suitable example using

MongoDB

Title: Map reduce

Name : Bora Mayur Rajendra

Roll No : 12

Batch : T1

Performed On :

***********************************************************

gurukul@ubuntu:~$ cd mongodb-linux-i686-2.4.6/

gurukul@ubuntu:~/mongodb-linux-i686-2.4.6$ cd bin

gurukul@ubuntu:~/mongodb-linux-i686-2.4.6/bin$ cd --dbpath mayur

bash: cd: --: invalid option

cd: usage: cd [-L|[-P [-e]]] [dir]

gurukul@ubuntu:~/mongodb-linux-i686-2.4.6/bin$ ./mongod --dbpath mayur

Fri Sep 30 11:01:07.472

Fri Sep 30 11:01:07.472 warning: 32-bit servers don't have journaling

enabled by default. Please use --journal if you want durability.

Fri Sep 30 11:01:07.472

Fri Sep 30 11:01:07.498 [initandlisten] MongoDB starting : pid=3697

port=27017 dbpath=mayur 32-bit host=ubuntu

Fri Sep 30 11:01:07.498 [initandlisten]

Fri Sep 30 11:01:07.498 [initandlisten] ** NOTE: This is a 32 bit MongoDB

binary.

Fri Sep 30 11:01:07.498 [initandlisten] ** 32 bit builds are

limited to less than 2GB of data (or less with --journal).

Fri Sep 30 11:01:07.498 [initandlisten] ** Note that journaling

defaults to off for 32 bit and is currently off.

Fri Sep 30 11:01:07.498 [initandlisten] ** See

http://dochub.mongodb.org/core/32bit

Fri Sep 30 11:01:07.498 [initandlisten]

Fri Sep 30 11:01:07.498 [initandlisten] db version v2.4.6

Fri Sep 30 11:01:07.498 [initandlisten] git version:

b9925db5eac369d77a3a5f5d98a145eaaacd9673

Fri Sep 30 11:01:07.498 [initandlisten] build info: Linux bs-

linux32.10gen.cc 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008

i686 BOOST_LIB_VERSION=1_49

Fri Sep 30 11:01:07.498 [initandlisten] allocator: system

Fri Sep 30 11:01:07.499 [initandlisten] options: { dbpath: "mayur" }

Fri Sep 30 11:01:07.702 [websvr] admin web console waiting for

connections on port 28017

Fri Sep 30 11:01:07.702 [initandlisten] waiting for connections on port

27017

Fri Sep 30 11:01:16.614 [initandlisten] connection accepted from

127.0.0.1:47208 #1 (1 connection now open)

Fri Sep 30 11:02:42.555 [conn1] end connection 127.0.0.1:47208 (0

connections now open)

Fri Sep 30 11:02:47.659 [initandlisten] connection accepted from

127.0.0.1:47209 #2 (1 connection now open)

Page 40: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

Fri Sep 30 11:03:38.565 [conn2] build index t1.b16 { _id: 1 }

Fri Sep 30 11:03:38.566 [conn2] build index done. scanned 0 total

records. 0.001 secs

Fri Sep 30 11:01:07.498 [initandlisten]

Fri Sep 30 11:01:07.498 [initandlisten] ** NOTE: This is a 32 bit MongoDB

binary.

Fri Sep 30 11:01:07.498 [initandlisten] ** 32 bit builds are

limited to less than 2GB of data (or less with --journal).

Fri Sep 30 11:01:07.498 [initandlisten] ** Note that journaling

defaults to off for 32 bit and is currently off.

Fri Sep 30 11:01:07.498 [initandlisten] ** See

http://dochub.mongodb.org/core/32bit

Fri Sep 30 11:01:07.498 [initandlisten]

> use t1

switched to db t1

> t1.createColection("b16");

Fri Sep 30 11:03:14.161 ReferenceError: t1 is not defined

> db.createColection("b16");

Fri Sep 30 11:03:24.943 TypeError: Property 'createColection' of object

t1 is not a function

> t1.createCollection("b16");

Fri Sep 30 11:03:31.447 ReferenceError: t1 is not defined

> db.createCollection("b16");

{ "ok" : 1 }

> db.b16.insert({"pr":"rubber",qty:10});

> db.b16.insert({"pr":"pen",qty:20});

> db.b16.insert({"pr":"pencil",qty:30});

> db.b16.insert({"pr":"pen",qty:40});

> db.b16.insert({"pr":"pencil",qty:60});

> db.b16.insert({"pr":"pen",qty:50});

> db.b16.insert({"pr":"rubber",qty:80});

> > var map=function(){emit(this.pr,1)};

> var reduce=function(pr,value){return Array.sum(value);};

> db.b16.mapReduce(map,reduce,{out:"out1"});

{

"result" : "out1",

"timeMillis" : 122,

"counts" : {

"input" : 7,

"emit" : 7,

"reduce" : 3,

"output" : 3

},

"ok" : 1,

}

> db.out1.find();

{ "_id" : "pen", "value" : 3 }

{ "_id" : "pencil", "value" : 2 }

{ "_id" : "rubber", "value" : 2 }

***********************************************************

Page 41: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

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

Assignment : Group B-18

Problem Definition : Connectivity with MongoDB using any Java Application

Title: Java and MongoDB

Name : Bora Mayur Rajendra

Roll No : 12

Batch : T1

Performed On :

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

Java Code:

package group_B_18;

import com.mongodb.*;

public class GB18

{

public static void main(String args[])

{

try

{

MongoClient client=new MongoClient("localhost",27017);

DB db=client.getDB("t1");

DBCollection coll=db.createCollection("stud", null);

/*-----------------TO INSERT DOCUMENT IN COLLECTION----------

*/

BasicDBObject d1=new

BasicDBObject("name","Mayuri").append("Address","Yeola");

BasicDBObject d2=new

BasicDBObject("name","Chitrali").append("Address","Manmad");

coll.insert(d1);

coll.insert(d2);

/*-----------------TO SHOW DOCUMENT IN COLLECTION---------*/

DBCursor cursor=coll.find();

while(cursor.hasNext())

{

System.out.print("\n");

System.out.print(cursor.next());

}

/*-----------------TO UPDATE DOCUMENT IN COLLECTION---------

*/

BasicDBObject old=new BasicDBObject();

old.put("name", "Mayuri");

Page 42: Assignme · Oracle/MYSQL(ODBC/JDBC), SQL prompt to create data base tables insert, update data values, delete table, use table, select queries with/without where clauses. demonstrate

BasicDBObject updateDoc=new BasicDBObject();

updateDoc.put("name", "Mayu");

BasicDBObject updateObj=new BasicDBObject();

updateObj.put("$set",updateDoc);

coll.update(old,updateObj);

System.out.println("Update Document");

/*--------TO DROP DOCUMENT IN COLLECTION----*/

System.out.print("Document After removing first Document");

DBObject myDoc=coll.findOne();

coll.remove(myDoc);

}

catch(Exception e)

{

System.out.print(e);

}

}

}

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

Output:

{ "Address" : "Yeola" , "_id" : { "$oid" : "57dd998064a8e1e51172c739"} ,

"name" : "Mayu"}

{ "_id" : { "$oid" : "57dd998064a8e1e51172c73a"} , "name" : "Chitrali" ,

"Address" : "Manmad"}

{ "_id" : { "$oid" : "57dd99bc64a80d088af74780"} , "name" : "Mayuri" ,

"Address" : "Yeola"}

{ "_id" : { "$oid" : "57dd99bc64a80d088af74781"} , "name" : "Chitrali" ,

"Address" : "Manmad"}Update Document

Document After removing first Document

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