2. Stored Procedure
can be defined as a group of SQL statements performing
a particular task
used to group or batch a set of operations or queries to
be executed on a database server
Faster, more efficient than individual SQL query stmt
3. Characteristics of Stored Procedure
contain SQL statements using constructs and control
structures
be invoked by name in a application
allow an application program to run in two parts such as
the application on the client and the stored procedure on the
server
5. Benefits of Stored Procedure
Reduced network traffic
Enhanced hardware and software capabilities
Distributed computing
Increased security
Client need not have the privilege as DBA
Decrease in development cost
Reusing a common stored procedure
Centralized control
Security, administrator and maintenance in one
place at the server
8. Parameters of a stored procedure
Stored procedures can accept data in the form of input
parameters that are specified at execution time
There are three parameters
IN
cannot changed or reassigned within module
is constant
OUT
IN/OUT
9. Creating and executed
CallableStatement does not contain the stored procedure
itself only a call to it.
CallableStatement cst =
cn.preparedCall(“{call functioname(?,?)}”)
10. ResultSet
A default result set object cannot be updated or scrolled
backward and forward. By default the cursor moves
forward only.
The characteristics of ResultSet are
Scrollable
Updatable
Holdable
Check whether the cursor stays open after
a commit
16. Updatable “ResultSet”
update rows in a result set using JAVA code rather than
SQL commands.
update, insert, delete
17. Concurrency
Updatability require database write locks to provide
access to the underlying database. Because you cannot
have multiple write locks concurrently
Updatability in a result set is associated with
concurrency in database access.
Concurrency is a process wherein two events take place
in parallel
Two types:
CONCURRENCY.READ_ONLY
Result set cannot be modified
CONCURRENCY.UPDATABLE
Update, insert and delete can performed
18. Batch Update
can be defined as a set of multiple update statements
that is submitted to the database for processing as a
batch
Statement, PreparedStatement, CallableStatement obj
can be used to submit batch updates
19. Batch Update
Benefits:
allow to request records, bring them to the client, make
changes to the records on the client side, and then send
the updated record back to the data source at some
other time.
improve performance
no need to maintain a constant connection to the
database
20. Batch Update using “Statement ” interface
Disable the auto-commit mode
Create a Statement instance
Add SQL commands to the batch
Execute the batch commands
Commit the changes in the database
Remove the commands from the batch
26. Transactions
is a set of one or more statements that are executed
together as a unit
Ensures either all the statements in the set or none of
them are executed
bank funds tranfer
withdraw from one : completed
deposit to another: not
=> Fail
27. Properties of Transactions
Atomicity
all or none performed
Consistency
cannot break the rules such
as integrity constraints
Isolation
no conflicts between
concurrent transaction
Durability
recover committed transaction if needed