Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –

Slides:



Advertisements
Similar presentations
Java Database Connectivity (JDBC). 2/24 JDBC (Java DataBase Connectivity) - provides access to relational database systems JDBC is a vendor independent.
Advertisements

Database programming in Java An introduction to Java Database Connectivity (JDBC)
Java and Databases CS-328 Dick Steflik. Database Drivers Think of a database as just another device connected to your computer like other devices it has.
Distributed Application Development B. Ramamurthy.
Introduction to Structured Query Language (SQL)
1 JDBC Java Database Connectivity. 2 c.pdf
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
1 Lecture 29 More on JDBC Overview  Objectives of this lecture  JDBC and its Drivers  Connecting to Databases (Java’s Connection class)  Querying a.
CSE470 Software Engineering Fall Database Access through Java.
JDBC. In This Class We Will Cover: What SQL is What ODBC is What JDBC is JDBC basics Introduction to advanced JDBC topics.
JDBC Java API for Database Connectivity. Layout of this recitation Introduction to JDBC API JDBC Architecture Understanding the design of JDBC API –Classes.
Advanced OOP MCS-3 OOP BSCS-3 Lecture # 11. DATABASE CONNECTIVITY IN JAVA JDBC Programming JDBC (Java Database Connectivity) is the specification of a.
JDBC / ODBC JDBC is the java API that facilitate interaction of a java application with the DBMS. FIRST APPROACH:
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
1 CSC 440 Database Management Systems JDBC This presentation uses slides and lecture notes available from
Java Database Connectivity (JDBC) Francisco Pajaro Saul Acosta Nahum Quezada Manuel Rubio.
JDBC Java Database Connectivity. What is an RDBMS? Relational database management system. There are other kinds of DBMS. Access is a GUI on a JET RBDMS.
Java Database Connectivity Vijayan Sugumaran Department of DIS Oakland University.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java/jsp program to connect to any database.
© Wang Bin 2004 JDBC ----Java Database Connectivity.
CSE470 Software Engineering Fall Database Access through Java.
Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.
Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.
Database Programming in Java Corresponds with Chapter 32, 33.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
Designing and Developing WS B. Ramamurthy. Plans We will examine the resources available for development of JAX-WS based web services. We need an IDE,
Connecting to Oracle using Java November 4, 2009 David Goldschmidt, Ph.D. David Goldschmidt, Ph.D.
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.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
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.
Accessing Database using JDBC. JDBC Objectives Gain basic knowledge of Java JDBC Become familiar with the basics of interacting with a database using.
COMP201 Java Programming Topic 15: Database Connectivity JDBC Reading: Chapter 4, Volume 2.
WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.
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.
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.
JDBC CS 124. JDBC Java Database Connectivity Database Access Interface provides access to a relational database (by allowing SQL statements to be sent.
JDBC CHAPTER-2. JDBC - Java Database Connectivity. JDBC from Sun Microsystems provides API or Protocol to interact with different databases. With the.
12/6/2015B.Ramamurthy1 Java Database Connectivity B.Ramamurthy.
Java and Databases. JDBC Architecture Java Application JDBC API Data Base Drivers AccessSQL Server DB2InformixMySQLSybase.
COMP 321 Week 4. Overview Normalization Entity-Relationship Diagrams SQL JDBC/JDBC Drivers hsqldb Lab 4-1 Introduction.
UNIT III - JDBC JDBC Overview – JDBC implementation – Connection class – Statements - Catching Database Results, handling database Queries. Networking–
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 CS 260 Database Systems. Overview  Introduction  JDBC driver types  Eclipse project setup  Programming with JDBC  Prepared statements  SQL.
CSI 3125, Preliminaries, page 1 JDBC. CSI 3125, Preliminaries, page 2 JDBC JDBC stands for Java Database Connectivity, which is a standard Java API (application.
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. JDBC provides Java applications with access to most database systems via SQL The architecture and API closely resemble.
Advanced Java Session 5 New York University School of Continuing and Professional Studies.
Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming.
1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 8: Applications Programming for Relational Databases Instructor’s.
JDBC. SQL(Structured Query Language) is divided into 1.DDL(Data Definition Language) create db, create table, alter table, drop db or table 2.DML(Data.
1 JDBC – Java Database Connectivity CS , Spring 2010.
Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL.
Java and database. 3 Relational Databases A relational Database consists of a set of simple rectangular tables or relations The column headings are.
JDBC. Database is used to store data permanently. These days almost all Applications needs database to store its data persistently. Below are the most.
JDBC.
DEPTT. OF COMP. SC & APPLICATIONS
Lec - 14.
JDBC Database Management Database connectivity
JDBC – Java Database Connectivity
Objectives In this lesson, you will learn about:
Interacting with Database
JDBC – ODBC DRIVERS.
Java Database Connectivity
Presentation transcript:

Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. – This driver acts as an intermediary between your application and the database. – There are actually several types of JDBC drivers available, so you need to choose the one that best suits your particular circumstances. – You also need to be aware that not all driver types are supported by Oracle, – and even when a driver type is supported by Oracle, it may not be supported by all versions of Oracle

Advance Computer Programming Driver Types – Sun has defined four categories of JDBC drivers, differences in architecture for the drivers. – One difference between architectures lies in whether a given driver is implemented in native code or in Java code. – For example, a driver may be written in C and then compiled to run on a specific hardware platform. – Another difference lies in how the driver makes the actual connection to the database. – The four driver types are as follows:

Advance Computer Programming Type 1: JDBC bridge driver – This type uses bridge technology to connect a Java client to a third-party API such as Oracle Database Connectivity (ODBC). – Sun's JDBC-ODBC bridge is an example of a Type 1 driver. These drivers are implemented using native code.

Advance Computer Programming Type 2: Native API (part Java driver) – This type of driver wraps a native API with Java classes – The Oracle Call Interface (OCI) driver is an example of a Type 2 driver. Because a Type 2 driver is implemented using local native code, – it is expected to have better performance than a pure Java driver.

Advance Computer Programming Type 3: Network protocol (pure Java driver). – This type of driver communicates using a network protocol to a middle-tier server. – The middle tier in turn communicates to the database. – Oracle does not provide a Type 3 driver. – however, have a program called Connection Manager that, when used in combination with Oracle's Type 4 driver, acts as a Type 3 driver in many respects.

Advance Computer Programming Type 4: Native protocol (pure Java driver) – This type of driver, written entirely in Java, communicates directly with the database. – No local native code is required. – Oracle's Thin driver is an example of a Type 4 driver. It's a popular notion that drivers implemented using native code are faster than pure Java drivers. because native code is compiled into the native op- code language of the computer, whereas Java drivers are compiled into byte code.

Advance Computer Programming SQL – SQL commands are divided into categories, the two main ones being Data Manipulation Language (DML) commands and Data Definition Language (DDL) commands – DML commands deal with data, either retrieving it or modifying it to keep it up-to-date – DDL commands create or change tables and other database objects such as views and indexes

Advance Computer Programming – A list of the more common DML commands follows: SELECT — used to query and display data from a database. The SELECT statement specifies which columns to include in the result set. The vast majority of the SQL commands used in applications are SELECT statements. INSERT — adds new rows to a table. INSERT is used to populate a newly created table or to add a new row (or rows) to an already- existing table. DELETE — removes a specified row or set of rows from a table UPDATE — changes an existing value in a column or group of columns in a table

Advance Computer Programming – The more common DDL commands follow: CREATE TABLE — creates a table with the column names the user provides. The user also needs to specify a type for the data in each column. Data types vary from one RDBMS to another, so a user might need to use metadata to establish the data types used by a particular database. CREATE TABLE is normally used less often than the data manipulation commands because a table is created only once, whereas adding or deleting rows or changing individual values generally occurs more frequently. DROP TABLE — deletes all rows and removes the table definition from the database.. However, support for the CASCADE and RESTRICT options of DROP TABLE is optional. In addition, the behavior of DROP TABLE is implementation-defined when there are views or integrity constraints defined that reference the table being dropped. ALTER TABLE — adds or removes a column from a table. It also adds or drops table constraints and alters column attributes

Advance Computer Programming JDBC Versions – Sun Microsystems released JDBC as part of JDK 1.1 on February 19, 1997 – The JDBC classes are contained in the Java package java.sql and javax.sqljava.sqljavax.sql – Starting with version 3.1, JDBC has been developed under the Java Community Process. Previous Release 3.6 Previous Release 3.7 Previous Release 4.0 Previous Release 4.1 Current Release 4.2 SP1

Advance Computer Programming Creating an ODBC Data Source 1.Click Start, point to Control Panel, double-click Administrative Tools, and then double-click Data Sources(ODBC). 2.Click the System DSN tab, and then click Add. 3.Click the database driver that corresponds with the database type to which you are connecting, and then click Finish. 4.Type the data source name. Make sure that you choose a name that you can remember. You will need to use this name later. 5.Click Select. 6.Click the correct database, and then click OK. 7.Click OK, and then click OK.

Advance Computer Programming Simple Database Acess import java.sql.*; public Connection conn; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn = DriverManager.getConnection("jdbc:odbc:AccessDB","",""); Statement stmt = conn.createStatement(); stmt.executeQuery("select * from Emp "); } catch(Exception e){ }

Advance Computer Programming Establishing Connections – First, establish a connection with the data source you want to use. – A data source can be a DBMS, a legacy file system, or some other source of data with a corresponding JDBC driver – This connection is represented by a Connection object. DriverManager: This fully implemented class connects an application to a data source, which is specified by a database URL.

Advance Computer Programming – When this class first attempts to establish a connection, it automatically loads any JDBC 4.0 drivers found within the class path – Note that your application must manually load any JDBC drivers prior to version 4.0. DataSource: This interface is preferred over DriverManager because it allows details about the underlying data source to be transparent to your application. – A DataSource object's properties are set so that it represents a particular data source.

Advance Computer Programming Creating Statements – A Statement is an interface that represents a SQL statement. – You execute Statement objects, and they generate ResultSet objects, which is a table of data representing a database result set. – For example, CoffeesTables.viewTable creates a Statement object with the following code: stmt = con.createStatement();

Advance Computer Programming – There are three different kinds of statements: Statement: Used to implement simple SQL statements with no parameters. PreparedStatement: (Extends Statement.) Used for precompiling SQL statements that might contain input parameters. See Using Prepared Statements for more information.Using Prepared Statements CallableStatement: (Extends PreparedStatement.) Used to execute stored procedures that may contain both input and output parameters. See Stored Procedures for more information.

Advance Computer Programming Executing Queries – To execute a query, call an execute method from Statement such as the following: – execute: Returns true if the first object that the query returns is a ResultSet object. Use this method if the query could return one or more ResultSet objects. – executeQuery: Returns one ResultSet object. – executeUpdate: Returns an integer representing the number of rows affected by the SQL statement. Use this method if you are using INSERT, DELETE, or UPDATE SQL statements.

Advance Computer Programming Closing Connections – When you are finished using a Statement, call the method Statement.close to immediately release the resources it is using – When you call this method, its ResultSet objects are closed. finally { if (stmt != null) { stmt.close(); }

Advance Computer Programming Metadata – Databases store user data, and they also store information about the database itself – Most DBMSs have a set of system tables, which list tables in the database, column names in each table, primary keys, foreign keys, stored procedures, and so forth. – Each DBMS has its own functions for getting information about table layouts and database features. – JDBC provides the interface DatabaseMetaData, which a driver writer must implement so that its methods return information about the driver and/or DBMS for which the driver is written.