Copyright  Oracle Corporation, 1998. All rights reserved. 2 Java and Databases: An Overview.

Slides:



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

Connecting to Databases. connecting to DB DB server typically a standalone application Server runs on localhost for smaller sites –i.e. Same machine as.
Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Java Database Connectivity (JDBC). 2/24 JDBC (Java DataBase Connectivity) - provides access to relational database systems JDBC is a vendor independent.
Database programming in Java An introduction to Java Database Connectivity (JDBC)
Distributed Application Development B. Ramamurthy.
SQL (Structured Query Language) X/OPEN Call Level Interface For SQL ODBC (Open DataBase Connectivity) API JDBC (Java DataBase Connectivity) API SQL (Structured.
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.
JDBC. In This Class We Will Cover: What SQL is What ODBC is What JDBC is JDBC basics Introduction to advanced JDBC topics.
SEMESTER 1, 2013/2014 DB2 APPLICATION DEVELOPMENT OVERVIEW.
JDBC / ODBC JDBC is the java API that facilitate interaction of a java application with the DBMS. FIRST APPROACH:
Dale Roberts 8/24/ Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Database Connectivity ODBC, JDBC and SQLJ CS2312.
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
September 6, 2015 Connecting Client Applications to Informix Databases using IBM Informix Connect and ODBC James Edmiston Database Consultant Quest Information.
© 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.
Dr R R DOCSIT, Dr BAMU. Basic Java : Introduction to JDBC 2 Objectives of This Session State what is Java Database Connectivity State different.
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,
CS 405G: Introduction to Database Systems Database programming.
 What software components are required?  How do I install the Oracle JDBC driver?  How do I connect to the database?  What form is the data in and.
Introduction to JDBC Michelle Lee, Ye Wu & Jeff Offutt SWE 432 Design and Implementation of Software for the Web.
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.
Copyright  Oracle Corporation, All rights reserved. 4 Accessing a Database Using JBCL.
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.
WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.
Copyright  Oracle Corporation, All rights reserved. 6 Accessing a Database Using the JDBC API.
Copyright  Oracle Corporation, All rights reserved. 7 Accessing a Database Using SQLJ.
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 CS 124. JDBC Java Database Connectivity Database Access Interface provides access to a relational database (by allowing SQL statements to be sent.
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.
12/6/2015B.Ramamurthy1 Java Database Connectivity B.Ramamurthy.
JDBC
Java and Databases. JDBC Architecture Java Application JDBC API Data Base Drivers AccessSQL Server DB2InformixMySQLSybase.
16 Java Database Connectivity. 2 Understand the JDBC Understand the steps of the JDBC: 1.) Importing packages 2.) Opening a connection to a database 3.)
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 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.
Database Programming With Java & JDBC Reading: DD Ch. 18, pp al/jdbc/index.html, or anything covering JDBC.
Introduction to JDBC Instructor: Mohamed Eltabakh 1.
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.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
2 Copyright © Oracle Corporation, All rights reserved. Basic Oracle Net Architecture.
12 Copyright © 2004, Oracle. All rights reserved. Application Migration: Overview.
Database: JDBC Overview
DEPTT. OF COMP. SC & APPLICATIONS
Note: To complete the examples in this section you need access to a database!! Most of the examples work for any database with JDBC drivers. However, connecting.
Interacting with Database
ODBC, OCCI and JDBC overview
JDBC Database Management Database connectivity
Database JDBC Overview CS Programming Languages for Web Applications
Introduction to Programming with Java
Objectives In this lesson, you will learn about:
Mr. Harish Sharma Asst. Professor Dept. of CA & IT SGRRITS Dehradun
Interacting with Database
JDBC – ODBC DRIVERS.
Java Database Connectivity
JAVA DATABaSE CONNECTIVITY
ODBC and JDBC.
Java API for Database Connectivity
Presentation transcript:

Copyright  Oracle Corporation, All rights reserved. 2 Java and Databases: An Overview

Copyright  Oracle Corporation, All rights reserved. 2-2 Objectives After completing this lesson, you should be able to do the following: Describe how to use JDBC to access a database from Java Describe how to use JBCL data components to access a database Describe how to use SQLJ to access a database After completing this lesson, you should be able to do the following: Describe how to use JDBC to access a database from Java Describe how to use JBCL data components to access a database Describe how to use SQLJ to access a database

Copyright  Oracle Corporation, All rights reserved. 2-3 Overview This lesson introduces the technologies involved in accessing databases from a Java program Database Applet or application JDBC

Copyright  Oracle Corporation, All rights reserved. 2-4 Accessing Databases in the Non-Java World Database vendors provide APIs that programs can call to access a database – Known as a Call Level Interface (CLI) – For example, Oracle Call Interface (OCI) Vendor provides a driver to receive CLI calls and forward to database Database vendors provide APIs that programs can call to access a database – Known as a Call Level Interface (CLI) – For example, Oracle Call Interface (OCI) Vendor provides a driver to receive CLI calls and forward to database Oracle OCI driver Oracle server Program Calls OCI functions

Copyright  Oracle Corporation, All rights reserved. 2-5 Dealing with Different Databases Different databases have their own CLI to access different databases Need to use different CLIs Need a driver for each CLI Different databases have their own CLI to access different databases Need to use different CLIs Need a driver for each CLI Oracle OCI driverOther driver Oracle Other db Program 1, calls OCI functions Program 2, calls other CLI functions

Copyright  Oracle Corporation, All rights reserved. 2-6 ODBC: A Standard CLI ODBC provides a standard interface to any database ODBC driver for OracleODBC driver for other db Oracle Other db ODBC Driver Manager Program 1, calls ODBC functions Program 2, calls ODBC functions

Copyright  Oracle Corporation, All rights reserved. 2-7 From ODBC to JDBC JDBC plays a similar role in Java JDBC defines standard interfaces and classes that you can call from Java JDBC plays a similar role in Java JDBC defines standard interfaces and classes that you can call from Java JDBC driver for OracleJDBC driver for other db Oracle Other db JDBC Driver Manager Java Program 1, uses JDBC classes/interfaces Java Program 2, uses JDBC classes/interfaces

Copyright  Oracle Corporation, All rights reserved. 2-8 What Is JDBC? JDBC defines standard interfaces Import java.sql package in a Java app Interfaces implemented by JDBC drivers JDBC defines standard interfaces Import java.sql package in a Java app Interfaces implemented by JDBC drivers interface Driver{…} interface Connection{…} interface Statement{…} interface ResultSet{…} class AAA implements Driver{…} class BBB implements Connection{…} etc… Example JDBC interfaces JDBC driver, such as Oracle

Copyright  Oracle Corporation, All rights reserved. 2-9 Using JDBC A simplified example: A simplified example: import java.sql.*; public class MyClass { public void MyMethod() { Connection con = DriverManager.getConnection(…); Statement st = con.createStatement(); ResultSet res; res = st.executeQuery("select * from emp"); // … Loop through result set, one row at a time

Copyright  Oracle Corporation, All rights reserved Oracle JDBC Drivers Oracle provides two different types of JDBC driver – “JDBC Thin” driver – “JDBC OCI” driver Use one or the other, depending on which type of Java program you are building Oracle provides two different types of JDBC driver – “JDBC Thin” driver – “JDBC OCI” driver Use one or the other, depending on which type of Java program you are building

Copyright  Oracle Corporation, All rights reserved Oracle JDBC Thin Driver The Oracle JDBC Thin driver is written in 100% pure Java Can be downloaded over the network, with a Java applet Use this driver for Java applets or applications The Oracle JDBC Thin driver is written in 100% pure Java Can be downloaded over the network, with a Java applet Use this driver for Java applets or applications Oracle JDBC Thin driver Oracle Java applet or application

Copyright  Oracle Corporation, All rights reserved Oracle JDBC OCI Driver The Oracle JDBC OCI driver makes OCI calls to a preinstalled “native” driver on the client Use for Java applications only The Oracle JDBC OCI driver makes OCI calls to a preinstalled “native” driver on the client Use for Java applications only oci803jdbc.dll Java application Oracle JDBC OCI driver Oracle

Copyright  Oracle Corporation, All rights reserved AppBuilder Support for JDBC AppBuilder for Java includes: – JDBC classes / interfaces in java.sql – Sun JDBC-ODBC Bridge driver The installation also provides: – Oracle Thin drivers for Oracle7 and Oracle8 – Oracle JDBC-OCI drivers for Oracle7 and Oracle8 AppBuilder for Java includes: – JDBC classes / interfaces in java.sql – Sun JDBC-ODBC Bridge driver The installation also provides: – Oracle Thin drivers for Oracle7 and Oracle8 – Oracle JDBC-OCI drivers for Oracle7 and Oracle8

Copyright  Oracle Corporation, All rights reserved AppBuilder Data Components The JavaBeans Component Library (JBCL) provides many data components – Some are visual “data-aware” controls – Some are nonvisual “worker” controls Allows a Java program to manipulate a database with the minimum of code – Hides much of the complexity The JavaBeans Component Library (JBCL) provides many data components – Some are visual “data-aware” controls – Some are nonvisual “worker” controls Allows a Java program to manipulate a database with the minimum of code – Hides much of the complexity

Copyright  Oracle Corporation, All rights reserved JBCL Data Components Example This applet connects to an Oracle8 database, and performs a simple query Results of query are displayed in a grid No code needed in this example This applet connects to an Oracle8 database, and performs a simple query Results of query are displayed in a grid No code needed in this example

Copyright  Oracle Corporation, All rights reserved Dynamic SQL in Java The JBCL data components use JDBC to achieve database connectivity The JDBC calls use “dynamic SQL” – SQL strings are parsed at run time – Not precompiled The JBCL data components use JDBC to achieve database connectivity The JDBC calls use “dynamic SQL” – SQL strings are parsed at run time – Not precompiled Statement stmt; stmt = conn.execute("select * from EMP " + "where SAL > 1000 " + "order by HIREDATE");

Copyright  Oracle Corporation, All rights reserved Static SQL in Java Oracle also provides the capability to provide “static SQL” in a Java program – SQL statements are precompiled, and converted to equivalent Java code – Allows SQL statements to be verified against database at compile time – Fewer run time errors This ability is provided by “SQLJ” Oracle also provides the capability to provide “static SQL” in a Java program – SQL statements are precompiled, and converted to equivalent Java code – Allows SQL statements to be verified against database at compile time – Fewer run time errors This ability is provided by “SQLJ”

Copyright  Oracle Corporation, All rights reserved SQL What Is SQLJ? SQLJ is a way to embed static SQL in Java programs Looks like standard Java, with a small number of localized extensions Translates embedded SQL into calls to JDBC SQLJ is a way to embed static SQL in Java programs Looks like standard Java, with a small number of localized extensions Translates embedded SQL into calls to JDBC

Copyright  Oracle Corporation, All rights reserved SQLJ Example A simplified example of how to use SQLJ Inserts a new row into emp table: A simplified example of how to use SQLJ Inserts a new row into emp table: import java.sql.*; import sqlj.runtime.ref.*; #sql { insert into EMP values('Thomas', 1200) }; afile.sqlj

Copyright  Oracle Corporation, All rights reserved Precompiling SQLJ Code SQLJ code must be precompiled to Java, using the SQLJ translator Checks the SQL code at compile time Converts afile.sqlj into afile.java Translates embedded SQL into appropriate calls to JDBC SQLJ code must be precompiled to Java, using the SQLJ translator Checks the SQL code at compile time Converts afile.sqlj into afile.java Translates embedded SQL into appropriate calls to JDBC SQLJ translator JDBC calls afile.sqlj afile.java

Copyright  Oracle Corporation, All rights reserved Summary JDBC defines a standard database interface for Java programs Two primary types of Oracle JDBC driver: JDBC Thin, and JDBC OCI AppBuilder for Java provides many data-aware components SQLJ can be used to embed static SQL code in Java programs JDBC defines a standard database interface for Java programs Two primary types of Oracle JDBC driver: JDBC Thin, and JDBC OCI AppBuilder for Java provides many data-aware components SQLJ can be used to embed static SQL code in Java programs

Copyright  Oracle Corporation, All rights reserved. 2-22