DBMS Po
DBMS Po
DBMS Po
NAME:
REG_NO:
SRIRAM ENGINEERING COLLEGE
Perumalpattu, Chennai-602 024.
REGISTER NO:
BONAFIDE CERTIFICATE
PAGE
EX.NO NAME OF THE PROGRAM
NO
2 Database Querying – Simple queries, Nested queries, Sub queries and Joins
6 Triggers
7 Exception Handling
EXTRA EXPERIMENTS
11 EMBEDDED SQL
EXAMPLE:
Table created.
OUTPUT:
SYNTAX:
datatype..); EXAMPLE:
values(2,’sharmi’,’tennis’,19);
OUTPUT:
1 Mercy Cricket
student; ID NAME
GAME AGE
1 Mercy cricket
2 Sharmi Tennis 19
SYNTAX:
EXAMPLE:
OUTPUT:
MODIFY
desc student;
Id Number(6)
Name
Varchar(20)
Game
Varchar(25) Age
Number(4)
DROP:
EXAMPLE:
SQL>drop table
student; SQL>Table
dropped.
TRUNCATE TABLE
DESC
Example: desc
Type
--------------------------------- --------
number(5) EName
VarChar(15)
number(3) PHONE_NO
number (10)
SQL> create table Archu (regno number(5), name varchar(20), dept varchar(5));
Table created.
INSERT COMMAND:
TYPE 1:
SQL> insert into Archu values('®no','&name','&dept');
Enter value for regno: 1
Enter value for name: Archu
Enter value for dept: CSE
old 1: insert into Archu values('®no','&name','&dept')
new 1: insert into Archu values('1','Archu','CSE')
1 row created.
SQL> /
Enter value for regno: 2
Enter value for name: Dharu
Enter value for dept: ECE
old 1: insert into Archu values('®no','&name','&dept')
new 1: insert into Archu values('2','Dharu','ECE')
1 row created.
TYPE 2:
TYPE 3:
DELETE COMMAND:
SQL>descArchu;
Name Null? Type
----------------------------------------- -------- ----------------------------
REGNO NUMBER(5)
NAME VARCHAR2(20)
DEPT VARCHAR2(20)
TRUNCATE COMMAND:
DROP COMMAND:
Q) Compute the total salary, average salary, max salary, min salary of all the employees of the company
Sql> SELECT AVG(salary), MAX(salary), MIN(salary), SUM(salary) FROM employees;
MIN(HIRE_DATE) MAX(HIRE_DATE)
17-JUN-87 21-APR-00
Total Employees
45
DEPARTMENT_ID AVG(SALARY)
100 8600
30 4150
7000
90 19333.3333
20 9500
70 10000
110 10150
50 3475.55556
80 8955.88235
40 6500
60 5760
10 4400
Queries:
Q1. Create a table called EMP with the following
structure. Name Type
---------- ----------------------
EMPNO NUMBER(6)
ENAME
VARCHAR2(20) JOB
VARCHAR2(10)
DEPTNO NUMBER(3)
SAL NUMBER(7,2)
Allow NULL for all columns except ename and job.
Solution:
1. Understand create table syntax.
2. Use the create table syntax to create the said tables.
3. Create primary key constraint for each table as understand from logical table
structure. Ans:
SQL> create table emp(empno number(6),ename varchar2(20)not null,job
varchar2(10) not null, deptno number(3),sal number(7,2));
Table created.
Q2: Add a column experience to the emp table. experience numeric null allowed.
Solution:
1. Learn alter table syntax.
2. Define the new column and its data type.
3. Use the alter table syntax.
Ans: SQL> alter table emp add(experience
number(2)); Table altered.
Q3: Modify the column width of the job field of emp table.
Solution:
1. Use the alter table syntax.
2. Modify the column width and its data type.
Ans: SQL> alter table emp modify(job
varchar2(12)); Table altered.
Q5: create the emp1 table with ename and empno, add constraints to check the empno
value while entering (i.e) empno > 100.
Solution:
1. Learn alter table syntax.
2. Define the new constraint [columns name type]
3. Use the alter table syntax for adding
constraints. Ans:
SQL> create table emp1(ename varchar2(10),empno number(6)
constraint check(empno>100));
Table created.
Q7: Truncate the emp table and drop the dept table
Solution:
id name
1 Abhi
2 Adam
4 Alex
COMMIT;
SAVEPOINT A;
SAVEPOINT B;
SAVEPOINT C;
id name
1 Abhi
2 Adam
4 Alex
5 Abhijit
6 Chris
7 Bravo
ROLLBACK TO B;
id name
1 Abhi
2 Adam
4 Alex
5 Abhijit
6 Chris
ROLLBACK TO A;
id name
1 Abhi
2 Adam
4 Alex
5 Abhijit
Queries(OUTPUT):
PID PNAME
---------- ----------
44 raj
66 pen
55 pencil
99 eraser
6 rows selected.
Table created.
Table altered.
CUSID CUSNAME
---------- ----------
33 df
11 kumar
44 raj
66 bharath
PID PNAME
---------- ----------
44 raj
66 pen
55 pencil
99 eraser
99 eraser
11 kumar
33 df
6 rows selected.
Table created.
Table altered.
SQL> create table pt2(cid integer primary key,cname char(10),pid integer,
2 constraintfk foreign key(pid) references pt1(pid));
Table created.
SQL> create table pt2(cid integer primary key,cname char(10),pid integer,
2 constraintfk foreign key(pid) references pt1(pid));
Table created.
ID NAME AGE
---------- ---------- ----------
11 kumar 30
12 raj 34
13 mom 56
ID PNAME
---------- ----------
11 pencil
SQL> select b.id,b.pname from customer a,productt b where a.id>12;
ID PNAME
---------- ----------
11 pencil
15 pen
22 eraser
55 kite
SQL> select id from customer where id in (select id from productt where id>10);
ID
----------
11
SQL> select a.id,b.pname from customer a,productt b where a.id=any(select b.id
2 fromproductt where id>12);
ID PNAME
---------- ----------
11 pencil
SQL> select id from customer where id in (select id from productt where id>10);
ID
----------
11
SQL> select id from customer where id=any(select id from productt where id>10);
ID
----------
11
PNAME
----------
pencil
pen
eraser
kite
SQL> select b.pname from productt b where b.id in(select a.id from customer a wh
ere a.id=b.id);
PNAME
----------
pencil
Subqueries with the INSERT Statement
Syntax:
1. INSERT INTO table_name (column1, column2, column3....)
2. SELECT *
3. FROM table_name
4. WHERE VALUE OPERATOR
QUERIES(OUTPUT):
INDEX:
SQL> create table Cstomer(ID number(3),Name char(10),Age number(4));
Table created.
1 row created.
SQL> /
Enter value for id: 12
Enter value for name: Abi
Enter value for age: 23
old 1: insert into Cstomer(ID,Name,Age)values(&ID,'&Name',&Age)
new 1: insert into Cstomer(ID,Name,Age)values(12,'Abi',23)
1 row created.
SQL> /
Enter value for id: 13
Enter value for name: Akshaya
Enter value for age: 25
old 1: insert into Cstomer(ID,Name,Age)values(&ID,'&Name',&Age)
new 1: insert into Cstomer(ID,Name,Age)values(13,'Akshaya',25)
1 row created.
SQL> /
Enter value for id: 14
Enter value for name: Prasha
Enter value for age: 26
old 1: insert into Cstomer(ID,Name,Age)values(&ID,'&Name',&Age)
new 1: insert into Cstomer(ID,Name,Age)values(14,'Prasha',26)
1 row created.
SQL> /
Enter value for id: 15
Enter value for name: Meena
Enter value for age: 24
old 1: insert into Cstomer(ID,Name,Age)values(&ID,'&Name',&Age)
new 1: insert into Cstomer(ID,Name,Age)values(15,'Meena',24)
1 row created.
ID NAME AGE
---------- ---------- ----------
11 Vena 20
12 Abi 23
13 Akshaya 25
14 Prasha 26
15 Meena 24
Index created.
Index created.
Index dropped.
Index dropped.
VIEWS:
View created.
ID
----------
11
12
13
14
15
View created.
ID NAME
---------- ----------
11 Vena
12 Abi
13 Akshaya
14 Prasha
15 Meena
SQL>
Index created.
Index created.
Index dropped.
Index dropped.
View created.
ID
----------
11
12
13
14
15
View created.
ID NAME
---------- ----------
11 Vena
12 Abi
13 Akshaya
14 Prasha
15 Meena
1 row updated.
SQL> select *from v2;
ID NAME
---------- ----------
11 Nivi
12 Abi
13 Akshaya
14 Prasha
15 Meena
1 row deleted.
ID NAME
---------- ----------
11 Nivi
12 Abi
14 Prasha
15 Meena
View dropped.
SEQUENCE:
Table created.
Sequence created.
1 row created.
1 row created.
ID NAME
---------- -----
1 Ram
2 Mani
SYNONYM:
Synonym created.
Synonym created.
no rows selected
ID NAME
---------- -----
1 Ram
2 Mani
1 row deleted.
1 row deleted.
no rows selected
Table dropped.
Synonym dropped.
Output:
Implicit cursor Program:
+----+----------+-----+-----------+----------+
+----+----------+-----+-----------+----------+
| 6 | Komal | 22 | MP | 4500.00 |
+----+----------+-----+-----------+----------+
DECLARE
total_rowsnumber(2);
BEGIN
UPDATE customers
IF sql%notfound THEN
total_rows := sql%rowcount;
END IF;
END;
When the above code is executed at the SQL prompt, it produces the following result −
6 customers selected
If you check the records in customers table, you will find that the rows have been updated −
Select * from customers;
+----+----------+-----+-----------+----------+
+----+----------+-----+-----------+----------+
| 6 | Komal | 22 | MP | 5000.00 |
+----+----------+-----+-----------+----------+
Explicit Cursors:
Program:
DECLARE
c_idcustomers.id%type;
c_namecustomers.name%type;
c_addrcustomers.address%type;
CURSOR c_customers is
BEGIN
OPEN c_customers;
LOOP
END LOOP;
CLOSE c_customers;
END;
When the above code is executed at the SQL prompt, it produces the following result −
1 Ramesh Ahmedabad
2 Khilan Delhi
3 kaushik Kota
4 Chaitali Mumbai
5 Hardik Bhopal
6 Komal MP
OUTPUT:
Procedures Programs:
Program1:
2 AS
3 BEGIN
4 dbms_output.put_line('Hello World!');
5 END;
6 /
Procedure created.
Hello World!
Program2:
SQL> DECLARE
2 a number;
3 b number;
4 c number;
7 BEGIN
8 IF x < y THEN
9 z:= x;
10 ELSE
11 z:= y;
12 END IF;
13 END;
15 BEGIN
16 a:= 23;
17 b:= 45;
18 findMin(a, b, c);
19 dbms_output.put_line(' Minimum of (23, 45) : ' || c);
20 END;
21 /
Program3:
a)SQL> DECLARE
2 a number;
4 BEGIN
5 x := x * x;
6 END;
7 BEGIN
8 a:= 23;
9 squareNum(a);
11 END;
12 /
SQL> declare
2 a number;
3 b number;
4 i number;
5 begin
6 i:=#
7 a:=i;
8 b:=0;
9 while a>0
10 loop
11 b:=b+power(mod(a,10),3);
12 a:=trunc(a/10);
13 end loop;
14 if b=i then
16 else
18 end if;
19 end
;
20 /
new 6: i:=123;
SQL> /
new 6: i:=407;
SQL> declare
2 a number;
3 b number;
4 i number;
5 n number;
6 s number;
7 begin
8 a:=&ulimit;
9 b:=&llimit;
10 n:=&n;
11 for i in a..b
loop 12 s:=i*n;
13 dbms_output.put_line(i||'*'||n||'='||s);
14 end loop;
15 end
;
16 /
1 old 8: a:=&ulimit;
new 8: a:=1;
10 old 9: b:=&llimit;
new 9: b:=10;
5
old 10: n:=&n;
2*5=10
3*5=15
4*5=20
5*5=25
6*5=30
7*5=35
8*5=40
9*5=45
10*5=50
2 salary number;
3 bonus number;
4 begin
5 salary:=&sa;
6 if salary>5000 then
7 bonus:=salary*0.5;
8 else
9 bonus:=0;
10 end if;
11 dbms_output.put_line(bonus);
12 End;
13 /
new 5: salary:=10000;
5000
2 K NUMBER;
3 BEGIN
4 K:=N*1000;
5 RETURN K;
6 END;
7 /
Function created.
F1(5)
----------
5000
Table created.
1 row created.
1 row created.
2 50 50 300
2 numres.num%type;
3 m1 res.MARk1%type;
4 m2 res.MARk2%type;
5 p number;
6 begin
7 select num, MARk1, MARk2 into num, m1, m2 from res where num=no;
8 p:=(m1+m2)/2;
9 return p;
10 end pro;
11 /
Function created.
SQL> select pro(1) from res;
PRO(1)
----------
150
150
PRO(2)
----------
50
50
Program3: (Factorial calcuation using Recursive Functions)
The following program calculates the factorial of a given number by calling itself recursively:
SQL> DECLARE
2 num number;
3 factorial number;
6 RETURN number
7 IS
8 f number;
9 BEGIN
10 IF x=0 THEN
11 f := 1;
12 ELSE
13 f := x * fact(x-1);
14 END IF;
15 RETURN f;
16 END;
17
18 BEGIN
19 num:= 6;
20 factorial := fact(num);
22 END;
23 /
Factorial 6 is 720
Program 1: (row level trigger for the customers table and perform inset and update operations)
Table created.
SQL>
1 row created.
1 row created.
11 ram 12 no st 1000
5 DECLARE
6 sal_diff number;
7 BEGIN
13 /
Trigger created.
Old salary:
Salary difference:
1 row created.
11 ram 12 no st 1000
7 Kriti 22 HP 7500
3 WHERE id = 11;
1 row updated.
11 ram 12 no st 1500
7 Kriti 22 HP 7500
2 AFTER
3 DELETE ON customers
5 BEGIN
6 IF :old.id = 11 THEN
8 END IF;
9 END;
10 /
Trigger created.
ERROR at line 1:
PROGRAM 1:
Table created.
1 row created.
1 row created.
ID NAME ADDRESS
11 kumar north st
12 kumar north st
SQL> DECLARE
2 c_idcustomers.id%type := 8;
3 c_namecustomers.name%type;
4 c_addrcustomers.address%type;
5 BEGIN
7 FROM customers
8 WHERE id = c_id;
12 EXCEPTION
16 dbms_output.put_line('Error!');
17 END;
18 /
No such customer!
The above program displays the name and address of a customer whose ID is given. Since there is no customer with
ID value 8 in our database, the program raises the run-time exception NO_DATA_FOUND, which is captured in
EXCEPTION block.
PROGRAM 2:
SQL> DECLARE
2 c_idcustomers.id%type := &cc_id;
3 c_namecustomers.name%type;
4 c_addrcustomers.address%type;
7 ex_invalid_id EXCEPTION;
8 BEGIN
9 IF c_id<= 0 THEN
10 RAISE ex_invalid_id;
11 ELSE
13 FROM customers
14 WHERE id = c_id;
18 END IF;
19 EXCEPTION
20 WHEN ex_invalid_id THEN
25 dbms_output.put_line('Error!');
26 END;
27 /
The above program display the result as ID must be greater than zero when we enter negative no
OUTPUT:
EXERCISES:
FIRST NORMAL FORM:
2 sname varchar2(20),
3 city varchar2(20),
4 state varchar2(20));
Type created.
2 enmae varchar2(20),
3 eadd address,
4 sal number(7,2))
SQL> /
Table created.
ENMAE VARCHAR2(20)
EADD ADDR
SAL NUMBER(7,2)
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> create table en1 as select eno, ename ,sal from employees;
Table created.
Table altered.
ENAME VARCHAR2(15)
SAL NUMBER(7,2)
Table created.
Table altered.
ENO NUMBER(3)
EADD ADDR
Normalizing to 1NF:
employee
1NF
Emp1 emp2
2 ename varchar2(20),
4 pname varchar2(20),
5 hours number(3));
Table created.
ENAME VARCHAR2(20)
PNO NUMBER(3)
PNAME VARCHAR2(20)
HOURS NUMBER(3)
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
Table created.
Table altered.
ENAME VARCHAR2(20)
Table created.
Table altered.
PNAME VARCHAR2(20)
Table created.
Table altered.
PNO NUMBER(3)
HOURS NUMBER(3)
Normalizing to 2NF:
2NF
Ep1
en Ename
o
Ep2
pn Pname
o
Ep3
en pno Hours
o
2 ename varchar2(20),
3 sal number(7),
4 dno number(3),
5 dname varchar2(20));
Table created.
ENAME VARCHAR2(20)
SAL NUMBER(7)
DNO NUMBER(3)
DNAME VARCHAR2(20)
1 row created.
SQL> /
1 row created.
Table created.
Table altered.
ENAME VARCHAR2(20)
SAL NUMBER(7,2)
DNO NUMBER(3)
Table created.
DNAME VARCHAR2(20)
Table altered.
Normalizing to 3NF:
Empdept
3NF
Ed1
Ed2
Dn Dname
o
OUTPUT:
Programs:
FORM 1:
Private Sub OK_Click()
If Text1.Text = "admin" Then
If Text2.Text = "admin" Then
MsgBox "welcome to user"
Form2.Show
Else
MsgBox " incorrect password"
End If
Else
MsgBox "incorrect User name"
End If
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub CANCEL_Click()
End
End Sub
FORM 2:
FORM 3:
Dim DB As Database
Dim RS As Recordset
Private Sub Form_Load()
Set DB = OpenDatabase("patientdsn", False, False, "ODBC;UID=secit1;PWD=secit1;")
Set RS = DB.OpenRecordset("select * from patient")
Text1.Text = RS(0)
Text2.Text = RS(1)
Text3.Text = RS(2)
Text4.Text = RS(3)
Text5.Text = RS(4)
End Sub
FORM 4 :
Dim DB As Database
Dim RS As Recordset
Private Sub Form_Load()
Set DB = OpenDatabase("staffdsn", False, False, "ODBC;UID=secit1;PWD=secit1;")
Set RS = DB.OpenRecordset("select * from staff")
Text1.Text = RS(0)
Text2.Text = RS(1)
Text3.Text = RS(2)
Text4.Text = RS(3)
Text5.Text = RS(4)
Text6.Text = RS(5)
End Sub
Form 2:
Form 3:
Form 4 :
Ex.No:10 Case Study using real life database applications
Abstract.
Introduction
One of the most important issues of modern computing systems is the pro-vision of sufficient
security and privacy guarantees for the user data. Security issues of mobile devices are discussed
in recent works In the field of databases and database management systems, security is a well
studied subject.. More recently, issues about privacy in database. However in the case of a mobile
database application there are additional security challenges due to the distributed nature of the
application and the hardware constraints of mo- bile devices.
Achieving a sufficient level of security for such a platform is an important problem which has to
be addressed.
For example, data privacy and confidentiality is identified in as one of the critical open issues and
research directions in mobile databases.
In this work, we consider mobile database applications and focus on the security issues that arise
in this context. For this aim we present a case study of a secure mobile database application. In
particular, we design, develop and test an electronic announcement board. A database server is
used for the central storage of all application data, while small-footprint relational databases are
used on the mobile clients. We identify a set of security issues and show how to handle these
issues on the prototype mobile application.
The rest of the paper is organized in the following way. The mobile database application is
described in Section 2. Security techniques are presented. The implementation and the test
platform are described presents possible attacks and how they are faced by the application and
Section 6 contains a final discussion.
The Mobile Database Application
We consider the following mobile database application (MDA): An electronic announcement board
where authorized users can publish and/or read announce- ments. There are two types of users
of the announcement board, author users and read-only users. The rights of a user are
determined by its type: An au- thor user has the right to create new announcements and to
modify or delete announcements authored by himself. A read-only user has the right to read all
announcements. The announcements are centrally stored in a database server and the users,
author users and read-only users, can use mobile devices to per- form their application related
operations remotely. The core of the application is build on mobile database technology. As
shown in Figure 1, the application uses the client-server model. From the user’s point of view
there are two main application components: An authoring tool for authoring announcements and
a viewer to access all announcements. Moreover, if the announcements are in- tended for public
access, then read-only access can also be provided through a web interface.
Read-Only Client
Major database management system (DBMS) vendors like Oracle, IBM and Microsoft, are
providing mobile extensions for their database servers. We have chosen a Pocket PC with
Windows Mobile 5.0 and SQL Server 2005 Mobile Edition as the computing platform for our mobile
application. However, cor- responding technologies of other vendors could also be used.
Motivation
In a mobile database application a part or a replica of the database is locally installed on the
mobile device. This is a significant difference compared to a con- ventional client-server
application where all data is centrally stored in a database server. The approach with a mobile
database provides the necessary autonomy to the mobile device to work independently from the
central database. The client application can work with the mobile database asynchronously, and
needs to connect to the central database only when it is necessary to synchronize. This approach
has several advantages compared to a conventional approach where the clients do not use local
storage:
–Efficiency: Except the synchronization steps, for all other operations the
client has immediate access to the data since it is locally stored on the
mobile device.
–Enhanced security: Disconnected computing reduces the total time that the
mobile device is exposed to potential attacks over the network.
–Energy efficiency: The mobile device has to operate its network system,
hardware and software, only during the synchronization operations.
–Reduced fees for network usage: This holds in the case where the usage of
the communication link is charged. If the network link up-time is charged
then the benefits are obvious. However, even if only the network traffic is charged, the
decentralized approach of a mobile database can still reduce network fees. In this case
the cost decrease is achieved by reducing the traffic volume between the mobile
device and the server.
Architecture
The architecture of the mobile database application (MDA) is shown in Figure 2. The
application uses the client-server model1. The server-side of the application has three
main components: A central database, a server agent and a web server. The central
database provides the central storage place for all announcements. The server agent
connects the central database with the web server. The web server provides the end-
point of the communication link that is used to transfer data between the mobile and
the central database.
Application
Client Server
Server Agent
Database
Mobile
Client Web Server
The client-side has also three main components: The client application, the client agent
and the mobile database. The client agent is responsible for the com- munication
between the mobile database and the central database and between the client
application and the mobile database. The client application is a mobile application with
a graphical user interface (GUI) that provides the necessary in- terface to the users for
using the application. The mobile database is a local small-footprint database on the
mobile device which replicates an appropriate part of the central database.
The mobile database application has to use a communication link between the client
and the server. The only requirement for the communication link is that it must
support the secure hypertext transfer protocol (https). There are currently several
1 Note that due to the existence of an agent at both endpoints of the communication
link, one could also argue that the actual application has three tiers. We prefer to
classify it as a conventional two-tier client-server application because in the mobile
database application the agents (middle tier) are transparent to the user and almost
transparent even to the application developer.most important are Wireless Network,
Bluetooth, GPRS and 3G. At both end- points of the communication link are agents of
the mobile database management system. We tested our application with a wireless
network connection and with a Bluetooth connection.
In this Section, we describe the security-related techniques that are applied in the
mobile database application.
The mobile database and the central database have to be synchronized at spe- cific
times. The synchronization is implemented in the system software of the mobile
database and is performed over the http protocol. Using http has the significant
advantage of using a widely available protocol and possibly the dis- advantage that its
performance may be lower than a proprietary protocol for the database
synchronization operation. We have selected the secure http protocol (https) to
perform the necessary synchronization operations between the mobile and the central
database. More precisely we use https with server and client authentication. This
choice assures:
The local database on the mobile device is encrypted and each time the user opens the
mobile database, he has to enter his password. In case the mobile device is stolen or
violated by an intruder, the data that is stored on the local database is not readable.
The encryption algorithm is part of SQL Server Mo- bile Edition and unfortunately we
were not able to find documentation for the specific algorithm. We assume that the
vendor does not simply rely on obscurity and that the encryption is based on one of the
established symmetric key en- cryption algorithms. If the build-in encryption
algorithm of the mobile database is considered insufficient, it is of course possible to
implement this feature within the client application.
The synchronization of the small-footprint database that is installed on the mo- bile
device with the central database is performed with database replication technology.
For this purpose, there is an appropriate publication at the database server. A
publication is the meta-data package of information about which data is replicated.
The mobile database uses the publication of the database server for the
synchronization operation. In order to connect to the publication an ap- propriate user
account on the database server has to be used. This means that the application user
has to be authenticated at the database server.
Both endpoints of the communication link are handled by mobile database agents.
During a synchronization process, the agent operations on the server-side can either
be executed by the default agent account of the server’s operating sys- tem or in the
context of a dedicated account of the server’s operating system. We use a dedicated
operating system account for the execution of the agent service. The account has been
granted the minimum permissions that are necessary for its role. This decision
satisfies the common security rule of granting minimum sufficient permissions.
Separate user accounts for the authoring and the read-only application
In case a user has to use the application both as an author of announcements and as a
reader of all announcements we can either assign two accounts to the user, an
authoring account and a read-only account, or grant both functionalities to a unique
user account. Even though the security of the application would not be lowered by
using a unique account, we preferred to use two separate, dedicated accounts. This
approach reflects in a more natural way the structure of the application.
For authoring operations, each user has access only to his own data. A set of database
triggers implemented in the database server, check that the data ma- nipulation
operations of the user are valid. This check prevents all users from accidental or
malicious modifications of data for which they have no authoriza- tion. More precisely,
an author
–can create new announcements that are signed with his name,
The above functionality resembles in a loose sense the virtual private database
technology (VPD) of Oracle.
The read-only part of the MDA is implemented as a separate client application. The
read-only client provides access for viewing all announcements. We apply certain
techniques to assure the security of the central database:
The announcements are also available over http as a web page. A dynamic web page
with aspx code gives a list of the announcements. The web server must have access to
the database in order to read the data. For this reason we have to deal with a common
security issue in database-driven web sites: Choosing the appropriate database
account that the web server is using to access the database. We created a specific
account in the database that has only one permission: To perform a select on the
replicated announcements table. This decision too, applies the principle of granting the
minimum sufficient permissions.
We also tested a common but very important feature, that of encrypting the user data
in the database. Even though this feature is not directly relevant to the
announcements application, we consider it very important for secure mobile database
applications and more generally for secure database applications. The user gives a
password to the client application and all his critical data is en- crypted at the client-
side before it is permanently stored in the database. This encryption guarantees the
confidentiality of the data against any database user including the local database
administrators. The approach is very simple: The client application applies a symmetric
key encryption algorithm, for example AES, and stores the encrypted data into the
database. When the user reads the data, he provides his password and the data is
decrypted. We verified this approach and it works transparently as soon as the user
has given his password. A shortage of the current mobile platform was that some
library functions, like for example the function ”PasswordDeriveBytes”, were not
provided by .NET Compact Framework v2.0. We overcame this problem by providing a
hand-coded implementation of the required function that was absent.
Implementation
Development
The development platform for the MDA was Visual Studio 2005 with cross com-
pilation for Windows Mobile 5.0 and the .NET Compact Framework v2.0. The
application is implemented in C# and the development follows the approach described
in [4].
Testing
The mobile database application (MDA) has first been tested on a Windows Mobile
Emulator and then on a real Pocket PC with Windows Mobile 5.0.
Visual
Studio 2005
ActiveSyn
c
Pocket PC
Device
SQL Server
2005
IIS
mobile application worked well. The mobile application on a Pocket PC with Windows
Mobile 5.0
Resistance in Attacks
• Eavesdropping for example with a sniffer: In https all traffic is encrypted and
hence, the confidentiality of the packet contents is protected.
• Fake client or server node: Using both the client and the server authen- tication
features of https (features that are provided by the Secure Sock- ets Layer - SSL)
assures the legitimacy of both the client and the server nodes. As already noted,
in the current version of the mobile database software, the client authentication
of https did not work properly within the synchronization process.
– Attack against the mobile device: The encryption of the mobile database
ensures the confidentiality of the local data in case the mobile device is stolen
or attacked.
• Stolen device: The local database that is installed on the mobile device is
encrypted and hence, if the device is stolen, the application data is not readable.
We note again, that the encryption is a feature of SQL Server Mobile and that we
were not able to find any documentation about the encryption algorithm that is
used.
• Network attack: The mobile database admits the client application to work while
the mobile device is disconnected. The mobile device has to enable its network
connection only during the synchronization operation of the mobile database.
However, even during the short period that the portable device uses its network
connection it can become the target of malicious software. In Windows Mobile
there is currently no build-in firewall but there are third-party products that can
cover this shortage. In any case the data that is stored in the mobile database is
encrypted and cannot be read.
– Attack against the server: The server computer where the server part of
the application is executed must permit network access, in particular incoming
connection requests, to its web server. Hence the server computer can become
the target of attacks against the web server. We apply common security
techniques to protect the server. Discussing these techniques is beyond the scope
of this paper. There are numerous sources for security of computing systems
offering web services.
Attack against the MDA: An important threat for any multi-user application comes from
the registered users of the application.
Attack from a read-only user: A read-only user can read all announce- ments. If a
read-only user attempts to modify the contents of the database he will not succeed.
First, the GUI of the client application does not pro- vide this feature. This prevents
unintentional attempts to modify data. Now, if a user intentionally uses some
proprietary software or a low-level database utility to modify the application data, he
will still fail because the publication at the database server is read-only. Finally, even if
any data would be modified (in some way that we did not predict), the change would
concern not the real database table, but a replicated table, that is used for the read-
only services.
• Attack from an author user: An author user has more permissions than a read-
only user. We consider what will happen if an author user attempts to perform
operations for which his is not authorized. In this case too, the GUI prevents
unintentional users attempts to perform illegal operations. For the case that
user intentionally attempts to modify data of other users by using some
proprietary software or a low-level database utility, a set of triggers in the
database server prohibits the unauthorized operationsDiscussion
Conclusion:
import java.io.*;
import java.sql.*;
public class jdeg
{
public static void main(String args[])throws IOException
{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
String rollno,nam,dep,mark;
System.out.println("enter the values(rno,name,dept,marks) to insert into the table");
rollno=br.readLine();
nam=br.readLine();
dep=br.readLine();
mark=br.readLine();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:stu");
Statement st = con.createStatement();
st.executeUpdate("insert into student
values('"+rollno+"','"+nam+"','"+dep+"','"+mark+"')");
ResultSet rs=st.executeQuery("select * from student");
System.out.println();
System.out.println();
System.out.println("RNO\tNAME\tDEPT\tMARKS");
while(rs.next())
{
System.out.print(rs.getString("rno")+"\t");
System.out.print(rs.getString("name")+"\t");
System.out.print(rs.getString("dept")+"\t");
System.out.println(rs.getString("marks")+"\t");
}
}
catch (Exception e)
{
System.out.println(e);
}
}
}
OUTPUT:
D:\jdk1.3\bin>edit jdeg.java
D:\jdk1.3\bin>javac jdeg.java
D:\jdk1.3\bin>java jdeg
Enter the values(rno,name,dept,mark)to insert into the table
67
murugan
cse
77
D:\jdk1.3\bin>
OUTPUT:
End Sub Private Sub clear_Click() Text1.Text = "" Text2.Text = "" Text3.Text = "" Text4.Text = ""
Text5.Text = "" Text6.Text = ""
End Sub Private Sub delte_Click() Adodc1.Recordset.Delete MsgBox "Record Deleted" If
Adodc1.Recordset.EOF = True
Then Adodc1.Recordset.MovePrevious End If
End
Sub Private Sub exit_Click() Unload Me
End Sub
Private Sub main_Click() Form1.Show
End Sub
Private Sub modify_Click() Adodc1.Recordset.Update End Sub
PROGRAM FOR FORM 3
Private Sub add_Click()
Adodc1.Recordset.AddNew MsgBox "Record added" End Sub
Private Sub clear_Click() Text1.Text = ""
Text2.Text = "" Text3.Text = "" Text4.Text = "" Text5.Text = "" Text6.Text = "" End Sub
Private Sub delte_Click()
Adodc1.Recordset.Delete MsgBox "Record Deleted" If Adodc1.Recordset.EOF = True
Then Adodc1.Recordset.MovePrevious End If
End Sub
Private Sub exit_Click() Unload Me
End Sub
Private Sub main_Click() Form1.Show
End Sub Private Sub modify_Click()
Adodc1.Recordset.Update End Sub
Output: