+ All Categories

Jdbc 2

Date post: 10-May-2015
Category:
Upload: tuan-ngo
View: 596 times
Download: 3 times
Share this document with a friend
Popular Tags:
30
JDBC [email protected] Session 2
Transcript
Page 1: Jdbc 2

JDBC

[email protected]

Session 2

Page 2: Jdbc 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

Page 3: Jdbc 2

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

Page 4: Jdbc 2

Characteristics of Stored Procedure

Page 5: Jdbc 2

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

Page 6: Jdbc 2

Create stored procedure using Statement obj Step 1:

Page 7: Jdbc 2

Create stored procedure using Statement obj Step 2:

Page 8: Jdbc 2

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

Page 9: Jdbc 2

Creating and executed CallableStatement does not contain the stored procedure itself only a call to it. CallableStatement cst = cn.preparedCall(“{call functioname(?,?)}”)

Page 10: Jdbc 2

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

Page 11: Jdbc 2

Scrollable ResultSet allows the cursor to be moved to any row in the result set.

Page 12: Jdbc 2

Scrollable ResultSet allows the cursor to be moved to any row in the result set.

Page 13: Jdbc 2

ResultSet constant values TYPE_FORWARD_ONLY TYPE_SCROLL_INSENSITIVE TYPE_SCROLL_SENSITIVE

Page 14: Jdbc 2

Row Positioning Methods method of ResultSet

Page 15: Jdbc 2

Row Positioning Methods method of ResultSet interface

Page 16: Jdbc 2

Updatable “ResultSet” update rows in a result set using JAVA code rather than SQL commands. update, insert, delete

Page 17: Jdbc 2

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

Page 18: Jdbc 2

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

Page 19: Jdbc 2

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

Page 20: Jdbc 2

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

Page 21: Jdbc 2

Batch Update using “Statement ” interface

Page 22: Jdbc 2

Batch Update using “Statement ” interface

Page 23: Jdbc 2

Batch Update using “Statement ” interface

Page 24: Jdbc 2

Batch Update using “PreparedStatement” interface

Page 25: Jdbc 2

Batch Update using “CallableStatement” interface

Page 26: Jdbc 2

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

Page 27: Jdbc 2

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

Page 28: Jdbc 2

Implementing Transaction using JDBC

Page 29: Jdbc 2

Implementing Transaction using JDBC

Page 30: Jdbc 2

Implementing Transaction using JDBC


Recommended