6-1 JAVA DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.

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)
Distributed Application Development B. Ramamurthy.
1 JDBC Java Database Connectivity. 2 c.pdf
JDBC Overview Autumn 2001 Lecturer: C. DeJong. Relational Databases widespread use used via SQL (Structured Query Language) freely available powerful.
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
EmbeddedSQL: 1 Impedance Mismatch Problem Problem : How to connect SQL statements with conventional programming languages Different models of language.
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.
UFCE4Y UFCE4Y-20-3 Components and Services Julia Dawson.
JDBC / ODBC JDBC is the java API that facilitate interaction of a java application with the DBMS. FIRST APPROACH:
Introduction to JDBC (Java Database Connectivity).
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
JDBC Vs. Java Blend Presentation by Gopal Manchikanti Shivakumar Balasubramanyam.
Java Database Connectivity (JDBC) Francisco Pajaro Saul Acosta Nahum Quezada Manuel Rubio.
Java Database Connectivity (JDBC). Introduction Database –Collection of data DBMS –Database management system –Storing and organizing data SQL –Relational.
1 Java Database Connection (JDBC) There are many industrial-strength DBMS's commercially available in the market. Oracle, DB2, and Sybase are just a few.
Helena Pomezná, ciz034 St. skupina: L392 FEI, VŠB-TUO Ak. rok. 2002/2003 Download:
Java Database Connectivity Vijayan Sugumaran Department of DIS Oakland University.
© Wang Bin 2004 JDBC ----Java Database Connectivity.
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.
Java Database Connectivity ASE. Java Database Connectivity (JDBC) l JDBC – provides an interface to Relational Data Sources l JDBC library provides the.
Database Programming in Java Corresponds with Chapter 32, 33.
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.
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.
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,
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.
1 JDBC Aum Amriteshwaryai Namah. 2 2 JDBC – Java DataBase Connectivity.
JDBC. Preliminaries Database Database Collection of data Collection of data DBMS DBMS Database management system Database management system Stores and.
COMP201 Java Programming Topic 15: Database Connectivity JDBC Reading: Chapter 4, Volume 2.
WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.
JDBC – Java Database Concentricity
JDBC Establish a connection with a database or access any tabular data source Send SQL statements Process the results Two major sets of interfaces: JDBC.
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.
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.
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–
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
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. Loading the driver import java.sql.*... Class.forName("org.postgresql.Driver")‏
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.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Java Database Connectivity.
1 JDBC – Java Database Connectivity CS , Spring 2010.
Java and database. 3 Relational Databases A relational Database consists of a set of simple rectangular tables or relations The column headings are.
DEPTT. OF COMP. SC & APPLICATIONS
Interacting with Database
Lec - 14.
JDBC Database Management Database connectivity
JDBC – Java Database Connectivity
JAVA Connection The following uses a ‘bridge’ between Java Database Connectivity (JDBC) and ODBC, namely sun.jdbc.odbc.JdbcOdbcDriver Supplied with the.
Design and Implementation of Software for the Web
Objectives In this lesson, you will learn about:
Interacting with Database
JDBC – ODBC DRIVERS.
Java Database Connectivity
Java API for Database Connectivity
Presentation transcript:

6-1 JAVA DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson

6-2 JDBC Introduction JDBC is a JAVA package (java.sql.*). The JDBC package contains the base API class. JDBC provides for a common DB interface. JDBC is in the public domain. Many vendors provide JDBC drivers. Focus of JDBC is on executing raw SQL and retrieving the results.

6-3 JDBC and SQL What type of SQL is acceptable? Many different SQL syntax's exists. With JDBC, SQL is just passed through. With JDBC, a query can even pass text and JDBC will not pass judgment on the text. JDBC API consists of a series of abstract Java interfaces.

6-4 JDBC-ODBC Bridge The bridge translates JDBC operations into ODBC operations. Use the sun.jdbc.odbc package to use the bridge. The Bridge is part of the Java SDK. The bridge does not work well with applets. The bridge is a reference driver so that other manufacturers can use it as a template.

6-5 JDBC Models JDBC supports a two-tier and three-tier model. Two Tier –Applets are allowed to connect directly to the database. –Use in a secure environment such as an intranet.

6-6 JDBC Models - Cont’d Three Tier –An application server written in Java mediates access to the database. –Java applet is downloaded to the client –This applet then talks to the Java server which talks to the database. –Used more for the Internet.

6-7 JDBC vs. ODBC JDBC does not use VOID*. At one point, developers attempted to map ODBC into Java. Java programming style is to use lots of smaller methods. ODBC uses a smaller number of procedures with a rich set of flags.

6-8 JDBC Classes JDBC consists of various class definitions in the java.sql package. JAVA JDBC Classes –java.sql.Date –java.sql.DriverManager –java.sql.DriverPropertyInfo –java.sql.Time –java.sql.Timestamp –java.sql.Types

6-9 Main JDBC Interfaces java.sql.CallableStatement java.sql.Connection java.sql. DatabaseMetaData java.sql.Driver java.sql.PreparedStatement java.sql.ResultSet java.sql.ResultSetMetaData java.sql.Statement

6-10 JDBC Exceptions java.sql.DataTruncation java.sql.SQLException –Always provides string describing error. –An error code. –Chain to next exception. java.sql.SQLWarning

6-11 DriverManager Class All database connections start with this class. This class keeps track of all loaded JDBC drivers. This class maps database URLs to a specific driver. Once an applet has a connection to a database, this class is no longer involved.

6-12 Database Connection Example Using the JDBC-ODBC bridge, the driver is loaded as follows: Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); Calling Class.forName will register it with the DriverManager. Once driver is loaded, to connect to database: String url = “jdbc.odbc:NwindDSN”; Connection con = DriverManager.getConnection ( url, “peterson”, “db_passwd”);

6-13 Database URLs JDBC allows you to use the database DSN. With JDB, you can also specify the target node, port, and connection attributes as part of the database name. Standard format for applets is: – : : –protocolname is always “jdbc” –subprotocol is database connect mechanism, e.g “odbc”

6-14 Connection Class This class obtains information about a specific database connection via the instantiated JDBC driver. A connection is a session with a database. This is where SQL statements are executed and results returned. With JDBC, multiple connections can be maintained with a single database. Connections can be specified as read only

6-15 Statement Class String createInventory = “CREATE TABLE Inventory “ + “(Inv_ID INTEGER, Item_Name “+ “VARCHAR(50), Price FLOAT, “+ “Cost FLOAT, Sup_ID INTEGER)”; Statement stmt = con.createStatement(); stmt.executeUpdate(createInventory) Stmt.executeUpdate(“INSERT INTO Inventory “+ “VALUES (202, ‘Widget A’, 19.95, “+ “16.50, 111)”);

6-16 PreparedStatement Class PreparedStatement updateInventory = con.prepareStatement( “UPDATE Inventory SET Price = Price * ? “ + “WHERE Item_Name LIKE ?”); To use the PreparedStatement, you must supply the values and the method. updateInventory.setFloat(1, 1.05); updateInventory.setString(2, “Wid”); updateInventory.executeUpdate();

6-17 CallableStatement Class CallableStatement cs = con.prepareCall( “{call DISPLAY_INVENTORY}”); ResultSet rs=cs.executeQuery(); String newProcedure = “create procedure DISPLAY_INVENTORY as “ + “select * from INVENTORY order by inv_ID”; Statement stmt=con.createStatement(); stmt.executeUpdate(newProcedure);

6-18 ResultSet Class This class is used to analyze results of a SQL select. A ResultSet maintains that cursor pointing to the current row of data. By using the various get methods, you can refer to specific columns by index or name.

6-19 ResultSetMetaData Class Used to describe a ResultSet object. Types of data that can be obtained are: –Catalog name of a specified column’s table –Number of columns in a ResultSet –Name of a column –Is auto-num on for a column –Can we put null entries in a column –etc

6-20 DatabaseMetaData Class Class is used to obtain information about an entire database. Typical types of information include: –Is database in read-only mode –The name of the database –Determine the database schemas –Obtain database URL