Helia / Martti Laiho, 1998-2000 JDBC Java Database Connection.

Slides:



Advertisements
Similar presentations
16 Copyright © 2005, Oracle. All rights reserved. Using JDBC to Access the Database.
Advertisements

Java II--Copyright © Tom Hunter. Chapter 18 JDBC.
Database By: Greg 4/10/2017 Java 9 - GUI.
Basic JDBC Celsina Bignoli What is JDBC Industry standard for database- connectivity between the Java language and a wide range of.
1 CSE5200 JDBC and JDeveloper JDBC java.sql package java.sql classes.
Fundamentals, Design, and Implementation, 9/e Chapter 12 ODBC, OLE DB, ADO, and ASP.
JDBC CS-328. JDBC Java API for accessing RDBMS Allows use of SQL for RDBMS programming Can be used for: –embedded SQL –execution of stored queries.
Object-Oriented Enterprise Application Development Advanced JDBC.
Java Database Connectivity JDBC ICW Lecture 12 Errol Thompson.
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
JDBC Java API for Database Connectivity. Layout of this recitation Introduction to JDBC API JDBC Architecture Understanding the design of JDBC API –Classes.
UFCE4Y UFCE4Y-20-3 Components and Services Julia Dawson.
Objectives Describe JDBC Describe JDBC Driver Types
JDBC / ODBC JDBC is the java API that facilitate interaction of a java application with the DBMS. FIRST APPROACH:
Accessing Databases with JDBC. Introduction to JDBC JDBC provides a standard library for accessing databases by using the JDBC API. JDBC standardizes.
Database applications with JDBC Jiafan Zhou. DBMS Database management systems (DBMS) is an organised collection of data. Usually database stores data.
Java Database Connectivity Vijayan Sugumaran Department of DIS Oakland University.
© Wang Bin 2004 JDBC ----Java Database Connectivity.
Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.
Java Database Connectivity ASE. Java Database Connectivity (JDBC) l JDBC – provides an interface to Relational Data Sources l JDBC library provides the.
What is JDBC? Java Database Connectivity (JDBC) is an API for the Java programming language that defines how a client may access a database. provides.
1 Java DataBase Connectivity JDBC java.sql.*. 2 Java DataBase Connectivity Draft release of JDBC spec (3/96) Java API for executing SQL statements (Since.
Active Server Pages ASP is Microsoft’s server-side script engine for dynamically-generated web pages. Most common language used is VBScript. If you use.
Dr R R DOCSIT, Dr BAMU. Basic Java : Introduction to JDBC 2 Objectives of This Session State what is Java Database Connectivity State different.
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.
CONTROLPANEL Java.sql package This package provides the APIs for accessing and processing data which is stored in the database especially relational.
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.
JDBC. JDBC stands for Java Data Base Connectivity. JDBC is different from ODBC in that – JDBC is written in Java (hence is platform independent, object.
1 JDBC Aum Amriteshwaryai Namah. 2 2 JDBC – Java DataBase Connectivity.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
JDBC. Preliminaries Database Database Collection of data Collection of data DBMS DBMS Database management system Database management system Stores and.
JDBC Enterprise Systems Programming. JDBC  Java Database Connectivity  Database Access Interface provides access to a relational database (by allowing.
WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.
JDBC Session 2 Tonight’s topics: 1.Prepared Statements 2.Transaction Processing 3.Callable Statements & Stored Procedures 4.Scrollable & Updatable Result.
JDBC – Java Database Concentricity
Copyright  Oracle Corporation, All rights reserved. 6 Accessing a Database Using the JDBC API.
Java Database Connectivity (JDBC). Topics 1. The Vendor Variation Problem 2. SQL and Versions of JDBC 3. Creating an ODBC Data Source 4. Simple Database.
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.
Copyright © 2002 ProsoftTraining. All rights reserved. Building Database Client Applications Using JDBC 2.0.
Chapter 17 Accessing Databases with JDBC. JDBC JDBC provides a standard library for accessing relational databases. By using the JDBC API, you can access.
JDBC Database Programming in Java Prepared by., Mrs.S.Amudha AP/SWE.
JDBC. Java.sql.package The java.sql package contains various interfaces and classes used by the JDBC API. This collection of interfaces and classes enable.
Session 30 Basics of JDBC. Java Simplified / Session 30 / 2 of 33 Review A Swing menu consists of a menubar, menuitems and menus. Trees are used to depict.
JDBC CHAPTER-2. JDBC - Java Database Connectivity. JDBC from Sun Microsystems provides API or Protocol to interact with different databases. With the.
JDBC By 朱志興. Four driver types of JDBC (1) JDBC-ODBC bridge plus ODBC driver: Java Database Client JDBC- ODBC bridge ODBC driver Database Server A B C.
1 Session 2 Module 3: Scrollable Resultset and Rowsets.
JDBC and SQLJ CIS 612 Spring JDBC JDBC is an API that enables database access from Java programs JDBC for DB access provides ◦ Portability across.
JDBC™ Advanced Concepts
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
Basics of JDBC.
Basics of JDBC Session 14.
JDBC (Java Database Connectivity)
CS122B: Projects in Databases and Web Applications Winter 2016
Adv Java Chapter 1.JDBC Chapter 2.Servlets Chapter 3.JSP.
JDBC - Resultset The java.sql.ResultSet interface represents the result set of a database query. A ResultSet object maintains a cursor that points to the.
Database Programming With Java & JDBC Reading: DD Ch. 18, pp al/jdbc/index.html, or anything covering JDBC.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Java Database Connectivity.
Java Database Connectivity JDBC. Open Database Connectivity developed by Microsoft to provide interaction with databases using SQL. Use the JDBC-ODBC.
Chapter 7 Chapter 7 Java Database Connectivity using JSP 1 (IS 203) WebProgramming (IS 203) Web Programming.
JDBC.
JDBC Java Data Base Connectivity נערך ע"י: אורי רוטנברג הנחיה: ד"ר תמר בניה קורס: סדנא ב-Java.
Introduction to Programming with Java
Design and Implementation of Software for the Web
Database Management Systems
Objectives In this lesson, you will learn about:
Interacting with Database
Java API for Database Connectivity
Presentation transcript:

Helia / Martti Laiho, JDBC Java Database Connection

Helia / Martti Laiho, Notes on JDBC - Java Database Connection Class Library: java.sql.* Literature/sources: SunSoft: JDBC Specification jdk1.3/docs/guide/jdbc/ JDBC Guide: Getting Started Seth White & al: JDBC TM API Tutorial and Reference, 2nd ed Horstmann & Cornell: Core JAVA Volume II Chapter 4 Orfali & Harkey: Client/Server Programming with JAVA and CORBA Siple: The Complete Guide to JAVA Database Programming, McGraw-Hill SOLID JDBC: sj23win.zip SOLID JDBC Driver Programmer’s Guide Melton & Eisenberg: Understanding SQL and Java Together

Helia / Martti Laiho, JDBC 1.0 API Designed by JavaSoft based on ISO SQL/CLI and Microsoft ODBC API provided in java.sql package 4 types of JDBC Driver implementation

Helia / Martti Laiho, Types of JDBC Implementations Java appl JDBC-ODBC bridge ODBC driver DBMS Java appl JDBC driver Native db-library DBMS Java appl JDBC server gateway DBMS Java appl DBMS Proprietary protocol Proprietary protocol JDBC driver JDBC driver DBMS- independent protocol DBMS- specific protocol Type 1 Type 2Type 3Type 4 - Melton & Eisenberg - Oracle JDBC/OCI - Oracle Thin JDBC - Sybase jConnect - Solid

Helia / Martti Laiho, SQL and Java data types SQL data type: INT[EGER] SMALLINT NUMERIC (m, n) DECIMAL (m, n) DEC (m, n) FLOAT (n) REAL DOUBLE CHAR[ACTER] (n) VARCHAR (n) DATE TIME TIMESTAMP Java data type: int short java.sql.BigDecimal double float double String java.sql.Date java.sql.Time java.sql.Timestamp

Helia / Martti Laiho, Java.sql - Interfaces / Methods... getMetaData() setAutoCommit(b) setTransaction Isolation(level) createStatement() prepareStatement(sql) prepareCall(sql) commit() rollback() close() setCursorName(s) executeQuery(sql) executeUpdate(sql) cancel() close() getMetaData() findColumn(name) next() getInt(col) getShort(col) getNumeric(col) getDouble(col) getFloat(col) getString(col) getDate(col) getTime(col) getTimestamp(col) wasNull() setText(s) append(s) close() SQLException getSQLState() getErrorCode() getNextExcetion() Driver Connection Statement ResultSetResultSetMetaData getColumnCount() getColumnName(i) getColumnLabel(i) getColumnDisplaySize(i) DatabaseMetaData getTables(…) … PreparedStatement … setXxxx(n, hvar) clearParameters() getConnection (url, user, psw) DriverManager Class CallableStatement registerOutputParameter execute()... getConnection (url, user, psw) DataSource

Helia / Martti Laiho, SQL Query String s; float n;... String query = "SELECT COF_NAME, PRICE FROM COFFEES"; ResultSet rs = stmt.executeQuery(query); while (rs.next()) { s = rs.getString("COF_NAME"); n = rs.getFloat("PRICE"); System.out.println(s + " " + n); } rs.close; COF_NAME PRICE snsn rs.next() rs.getString() rs.getFloat()

Helia / Martti Laiho, SQLQuery Sequence Diagram Client DriverManager Connection Statement ResultSet getConnection createStatement next getString getInt... close executeQuery adapted from Orfali & Harkey { [ Until next returns false ] }

Helia / Martti Laiho, Invoking a Stored Procedure Client DriverManager Connection Callable Statement Callable Statement getConnection prepareCall getString getInt... close execute... adapted from Orfali & Harkey parameters marked in the procedures call by ? placeholders are identified by the corresponding order numbers 1, 2,.. of the placeholders registerOutputParameter

Helia / Martti Laiho, JDBC Escape Syntax call{call proc (arg1, …) } ?=call{?= call proc (arg1, …) } d{d ‘yyyy-mm-dd’} escape{escape ‘%’} fn{fn function (arg1, …) } oj{oj outer-join } t{t ‘hh:mm:ss’} ts{ts ‘yyyy-mm-dd hh:mm:ss.fffff’}

Helia / Martti Laiho, Transactions Default: AutoCommit Isolation Levels: 0TRANSACTION_NONE 1TRANSACTION_READ_UNCOMMITTED 2TRANSACTION_READ_COMMITTED 3TRANSACTION_REAPEATABLE_READ 4TRANSACTION_SERIALIZABLE Methods: con.setAutoCommit(false); level = con.getTransactionIsolation(); con.setTransactionIsolation(level); con.commit(); con.rollback();

Helia / Martti Laiho, Exception handling try { jdbc method call... } catch (SQLException ex) { System.out.println (”\nSQLException:"); while (ex != null) { System.out.println (”SQLState: "+ex.getSQLState()); System.out.println (”Message: "+ ex.getMessage()); System.out.println (”Vendor: "+ ex.getErrorCode()); ex = ex.getNextException(); } catch (java.lang.Exception ex) { System.out.println("Exception: " + ex); ex.printStackTrace (); } - adapted from Core JAVA Vol II ch 4 p 206

Helia / Martti Laiho, JDBC 2.0 API JDBC 2.0 Core API (java.sql) –Scrollable ResultSet –Updating by ResultSet –Batch Updates –New SQL-99 datatypes JDBC 2.0 Standard Extension API (javax.sql)

Helia / Martti Laiho, Scrollable ResultSet Resultset types –TYPE_FORWARD_ONLY (~JDBC 1.0) –TYPE_SCROLL_INSENSITIVE –TYPE_SCROLL_SENSITIVE Methods –beforeFirst() (initially) –first() –next() ( JDBC 1.0) –previous() –last() –afterLast() –absolute (n | -n) –relative (n | -n) –getRow() –isFirst(), isLast(), isBeforeFirst(), isAfterLast() –moveToInsertRow(), moveToCurrentRow()

Helia / Martti Laiho, Updatable ResultSet Updatable –CONCUR_READ_ONLY (~JDBC 1.0) –CONCUR_UPDATABLE Methods –updateXXX(column, value) –… –updateRow() or cancelRowUpdates()

Helia / Martti Laiho, Inserting a new row InsertRow processing: –moveToInsertRow() –updateXXX(, ) …. –insertRow() –moveToCurrentRow() updateable row “Current row” “InsertRow buffer” moveToInsertRow() moveToCurrentRow() InsertRow() ResultSet:

Helia / Martti Laiho, Deleting a Row Positioning in the ResultSet and deleting: – –deleteRow() Note: –drivers handle deletions differently

Helia / Martti Laiho, Refreshing the row Applies only to Cursor type: –TYPE_SCROLL_SENSITIVE method –refreshRow()

Helia / Martti Laiho, Batch Updates Methods –addBatch(“….”) –… –executeBatch(); BatchUpdateException

Helia / Martti Laiho, SQL-1999 Datatypes BLOB - binary large objects CLOB - character large objects SQL Array - of any SQL scalar datatype SQL structured type - User Defined Type UDT SQL REF - identifier

Helia / Martti Laiho, JDBC 2.0 Standard Extension API JDBC 2.0 Standard Extension API i.e. Optional Package API –in javax.sql –JavaBeans: Rowsets –JNDI for naming and directory interface –Connection Pooling –Distributed Transactions: 2PC by Java Transaction API (JTA)