Assignment 3
Assignment 3
Read-Write Synchronization:
Write-Write Synchronization:
These two properties ensure that there can be no difference in the effects of the
two schedules.
1.Conflict serializability
2. View serializability
Conflict serializability:
A schedule is called conflict serializable if we can convert it into a serial
schedule after swapping its non-conflicting operations.
1. Both the operations should belong to different transactions.
2. Both the operations are working on same data item.
3. At least one of the operations is a write operation.
View serializability:
View Serializability is a process to find out that a given schedule is view
serializable or not.
Q2) JDBC Connectivity –Insert, Select, Delete, and Update with program
code and outputs.
JDBC INSERT:
import java.sql.*;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("
jdbc:oracle:thin:@localhost:1521:orcl", "121710303040", "password");
Statement stmt = con.createStatement();
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
JDBC SELECT :
import java.sql.*;
// SELECT query
String q1 = "select * from userid WHERE id = '" + id +
"' AND pwd = '" + pwd + "'";
ResultSet rs = stmt.executeQuery(q1);
if (rs.next())
{
System.out.println("User-Id : " + rs.getString(1));
System.out.println("Full Name :" + rs.getString(3));
System.out.println("E-mail :" + rs.getString(4));
}
else
{
System.out.println("No such user id is already registered");
}
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
Output : user id : 12171033040
Full name : naveenredmi9s
e-mail : [email protected]
JDBC DELETE :
import java.sql.*;
int x = stmt.executeUpdate(q1);
if (x > 0)
System.out.println("One User Successfully Deleted");
else
System.out.println("ERROR OCCURED :(");
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Output : One User Successfully Deleted
JDBC UPDATE :
import java.sql.*;
// Updating database
String q1 = "UPDATE userid set pwd = '" + newPwd +
"' WHERE id = '" +id+ "' AND pwd = '" + pwd + "'";
int x = stmt.executeUpdate(q1);
if (x > 0)
System.out.println("Password Successfully Updated");
else
System.out.println("ERROR OCCURED :(");
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Output : Password Successfully Updated
Q3) Explain Crash Recovery
Transaction failure
A transaction has to abort when it fails to execute or when it reaches a point from
where it can’t go any further. This is called transaction failure where only a few
transactions or processes are hurt.
Reasons for a transaction failure could be −
Logical errors − Where a transaction cannot complete because it has
some code error or any internal error condition.
System errors − Where the database system itself terminates an active
transaction because the DBMS is not able to execute it, or it has to stop
because of some system condition. For example, in case of deadlock or
resource unavailability, the system aborts an active transaction.
Binary lock
Compatibility lock
Binary lock :
A binary lock can have two states or values: locked and unlocked.
A distinct lock is associated with each database item A. If the value of the lock
on A is 1, item A cannot be accessed by a database operation that requests the
item. If the value of the lock on A is 0 then item can be accessed when requested.
We refer to the current value of the lock associated with item A as LOCK
(A). There are two operations, lock item and unlock item are used with binary
locking A transaction requests access to an item A by first issuing a lock item
(A) operation. If LOCK (A) = 1, the transaction is forced to wait. If LOCK (A) =
0 it is set to 1 (the transaction locks the item) and the transaction is allowed to
access item A. When the transaction is through using the item, it issues an
unlock item (A) operation, which sets LOCK (A) to 0 (unlocks the item) so
that A may be accessed by other transactions. Hence binary lock enforces mutual
exclusiol1 on the data item.
Compatibility lock :
Suppose that there are A and B two different locking modes. If a transaction T1
requests a lock of mode on item Q on which transaction T2 currently hold a
lock of mode B. If transaction can be granted lock, in spite of the presence of
the mode B lock, then we say mode A is compatible with mode B.
*****************************************************************************************