Jdbc 2


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Jdbc 2

  1. 1. JDBC Session 2 tnngo2@gmail.com
  2. 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. 3. Characteristics of Stored Procedure contain SQL statements using constructs and controlstructures be invoked by name in a application allow an application program to run in two parts such asthe application on the client and the stored procedure on theserver
  4. 4. Characteristics of Stored Procedure
  5. 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
  6. 6. Create stored procedure using Statement obj Step 1:
  7. 7. Create stored procedure using Statement obj Step 2:
  8. 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. 9. Creating and executed CallableStatement does not contain the stored procedure itself only a call to it. CallableStatement cst = cn.preparedCall(“{call functioname(?,?)}”)
  10. 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
  11. 11. Scrollable ResultSetallows the cursor to be moved to any row in the result set.
  12. 12. Scrollable ResultSetallows the cursor to be moved to any row in the result set.
  14. 14. Row Positioning Methods method of ResultSet
  15. 15. Row Positioning Methods method of ResultSet interface
  16. 16. Updatable “ResultSet” update rows in a result set using JAVA code rather than SQL commands. update, insert, delete
  17. 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. 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. 19. Batch UpdateBenefits: 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. 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
  21. 21. Batch Update using “Statement ” interface
  22. 22. Batch Update using “Statement ” interface
  23. 23. Batch Update using “Statement ” interface
  24. 24. Batch Update using “PreparedStatement” interface
  25. 25. Batch Update using “CallableStatement” interface
  26. 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. 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
  28. 28. Implementing Transaction using JDBC
  29. 29. Implementing Transaction using JDBC
  30. 30. Implementing Transaction using JDBC