JDBC IV IS 313 1.30.2003. Outline  Batch processing  Transactions  Homework #2  Examples.

Slides:



Advertisements
Similar presentations
JDBC – Java DataBase Connectivity CSE432 Object Oriented Software Engineering.
Advertisements

Java Database Connectivity JDBC ICW Lecture 12 Errol Thompson.
Three-Tier Architecture Oracle DB Server Apache Tomcat App Server Microsoft Internet Explorer HTML Tuples HTTP Requests JDBC Requests Java Server Pages.
Managing Concurrency in Web Applications. DBI 2007 HUJI-CS 2 Intersection of Concurrent Accesses A fundamental property of Web sites: Concurrent accesses.
Chapter 121 Adding Power to Database Access with JSP JavaServer Pages By Xue Bai.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.
Databases: Queries with Java Dr Andy Evans. JDBC SQL Three methods: Statements: Standard, simple, SQL. PreparedStatements: Compiled SQL statements that.
Lecture 4 PL/SQL language. PL/SQL – procedural SQL Allows combining procedural and SQL code PL/SQL code is compiled, including SQL commands PL/SQL code.
Stored Procedures, Transactions, and Error-Handling
MySQL, Java, and JDBC CSE 3330 Southern Methodist University.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 38 Advanced Java Database.
JDBC Tutorial MIE456 - Information Systems Infrastructure II Vinod Muthusamy November 4, 2004.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui COMP 302 Database Systems Java Data Base Connectivity Lecturer Dr Pavle Mogin.
CS 405G: Introduction to Database Systems Database programming.
Connecting to Oracle using Java November 4, 2009 David Goldschmidt, Ph.D. David Goldschmidt, Ph.D.
JDBC Java and Databases, including Postgress. JDBC l Developed by Industry leaders l Three main goals: –JDBC should be an SQL-level API –JDBC should capitalize.
1cs Intersection of Concurrent Accesses A fundamental property of Web sites: Concurrent accesses by multiple users Concurrent accesses intersect.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 33 Advanced Java.
JDBC Enterprise Systems Programming. JDBC  Java Database Connectivity  Database Access Interface provides access to a relational database (by allowing.
Chapter 8 Databases.
Copyright  Oracle Corporation, All rights reserved. 6 Accessing a Database Using the JDBC API.
Java Database Connectivity. Java and the database Database is used to store data. It is also known as persistent storage as the data is stored and can.
DAT602 Database Application Development Lecture 9 Advanced JDBC 2.
Leman Akoglu 11/11/ Fall 2009 Recitation Homework 9 Building A Web Application Phase-II School of Computer Science.
Copyright © 2002 ProsoftTraining. All rights reserved. Building Database Client Applications Using JDBC 2.0.
JDBC Database Programming in Java Prepared by., Mrs.S.Amudha AP/SWE.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Application Development Chapter 6 Sections –
JDBC CS 124. JDBC Java Database Connectivity Database Access Interface provides access to a relational database (by allowing SQL statements to be sent.
JDBC IV IS Outline  Quiz 1  Stored procedures  Batch processing  Transactions  Homework #2.
1 Database Application Development Chapter 6 Sections –
Tasks Needed for MissionMapEditor Martin Q. Zhao September 18, 2010.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L12_JDBC_MySQL 1 Transations.
1 Intro stored procedures Declaring parameters Using in a sproc Intro to transactions Concurrency control & recovery States of transactions Desirable.
Transactions, Roles & Privileges Oracle and ANSI Standard SQL Lecture 11.
Basics of JDBC.
JDBC (Java Database Connectivity)
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 8: Applications Programming for Relational Databases Instructor’s.
SQL and Java The vision for Java is to be the concrete and nails that people use to build this incredible network system that is happening all around us.
Web Programming Assistant Professor Xiaozhong Liu
Using Oracle JDBC How to Run JDBC on Your Account Communication Mechanism Using Metadata Building a Database Auto Commit v.s Atomic Transaction.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java program to connect to any database.
JDBC.
JDBC Java Data Base Connectivity נערך ע"י: אורי רוטנברג הנחיה: ד"ר תמר בניה קורס: סדנא ב-Java.
1. Writing a Java program to connect to SQL Server 2008 and Create a table Populate the table (insert data) Perform queries to retrieve information from.
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
CS320 Web and Internet Programming Database Access with JDBC Chengyu Sun California State University, Los Angeles.
JDBC III IS Outline  Scrollable ResultSets  Updatable ResultSets  Prepared statements  Stored procedures.
Instructor: Jinze Liu Fall /8/2016Jinze University of Kentucky 2 Database Project Database Architecture Database programming.
Transactions. Contents ● Transactions ● Save Points ● Batch Updates.
JDBC – Java DataBase Connectivity
CS3220 Web and Internet Programming Database Access with JDBC
Course Outcomes of Advanced Java Programming AJP (17625, C603)
DCL – Data Control Language
JDBC III IS
HW#4 Making Simple BBS Using JDBC
UNIT-2 Java Database Programming
JDBC – Java DataBase Connectivity
JDBC – Java DataBase Connectivity
Transactions Properties.
The PROCESS of Queries John Deardurff
The PROCESS of Queries John Deardurff Website: ThatAwesomeTrainer.com
The PROCESS of Queries John Deardurff
Understanding Core Database Concepts
CS3220 Web and Internet Programming Database Access with JDBC
CS3220 Web and Internet Programming Database Access with JDBC
JDBC – Java DataBase Connectivity
Presentation transcript:

JDBC IV IS

Outline  Batch processing  Transactions  Homework #2  Examples

Omission  Not every ResultSet is updatable usually when the query is a join

Distributed Application

Problem  Cost of moving data between client and server  One solution Stored procedure: move computation to data  Another Try to reduce the cost by reducing overhead Communication costs are “chunky”

Non-linear Communication Costs

Example  Suppose 12 small operations  Execution time = 12 * (op_time + comm_in + comm_out)  If grouped together = 12 * op_time + comm_in + comm_out

Steps 1. Turn off auto commit 2. For each update, call addBatch instead of executeUpdate 3. when complete, call executeBatch

Batch processing con.setAutoCommit(false); … JDBC calls … Statement stmt = con.prepareStatement (“INSERT...;”);... set parameters... // ready to update stmt.addBatch(); // instead of executeUpdate()... more stuff... stmt2.addBatch ();... more stuff... stmt3.addBatch (); // updates complete con.executeBatch(); con.setAutoCommit(true);

Summary - Batch Processing  Useful when there are many updates  Benefits Lower communication overhead to database  Problems Each statement treated separately  No chance to handle exceptions that affect later updates

Transactions  Goal In the face of machine failure, keep the database consistent

Transactions  Atomicity No partial success  Consistency End point is consistent  Isolation Transaction invisible until completed  Durability Committed actions survive system failure

Example  Reservation is added  Actions Record inserted into Reservation table Capacity table updated with new reservation count

Steps  1. Set auto commit to false  2. perform updates as normal  3. Commit transaction  4. Set auto commit back to true  If there is a failure, rollback the transaction typically exception handler

Example try { conn.setAutoCommit (false); addReservation (conn); updateCapacity (conn); conn.commit (); } catch (SQLException e) { try { conn.rollback (); DBUtilities.displaySQLException (e); } catch (SQLException e2) { DBUtilities.displaySQLException (e2); } } finally { try { conn.setAutoCommit (true); } catch (SQLException e3) { DBUtilities.displaySQLException (e3); } }

Metadata DatabaseMetaData metadata = con.getMetaData(); ResultSet tables = metadata.getTables(null, null, null, null, null); while (rs.next()) { System.out.println (tables.getString (“name”)); }

Homework #2  Hotel reservations  Database  Interactive text mode

Interaction % java HotelTextMode  add Enter first name: Jack Enter last name: Spratt Enter date of arrival (mm/dd/yy): 1/30/03 Enter room type: 0 Enter # of guests: 2 Enter number of days: 5  date Enter date to search (mm/dd/yy): 1/30/03 Reservation Id: 45 Customer: Jack Spratt Room: 0 Arrival: 1/30/03 2 guests, staying 5 days  delete Enter reservation id: 45  exit %

Commands  add  find by date  help  (exit)  (capacity)  delete  find by name  show all

How to design?

Adaptability  What are the most likely vectors of change?

Command Pattern  Represent users action with an object  Framework in which command objects are created and executed

Central Loop  Loop Create command object Set parameters Execute

Command Line Interaction % java HotelTextMode delete 37 %

Command Hierarchy

Advice  Start right away  Don’t use JDK 1.3  Close statements and result sets  Start right away

Programming example  Exit command  Capacity command