JDBC Enterprise Systems Programming. JDBC  Java Database Connectivity  Database Access Interface provides access to a relational database (by allowing.

Slides:



Advertisements
Similar presentations
CE203 - Application Programming Autumn 2013CE203 Part 51 Part 5.
Advertisements

Java Database Connectivity (JDBC). 2/24 JDBC (Java DataBase Connectivity) - provides access to relational database systems JDBC is a vendor independent.
JDBC - Java Database Connectivity The objectives of this chapter are: To describe the architecture of JDBC To outline the classes in the java.sql package.
Distributed Application Development B. Ramamurthy.
15-Jun-15 JDBC. JDBC is a Sun trademark It is often taken to stand for Java Database Connectivity Java is very standardized, but there are many versions.
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.
Java Database Connectivity (JDBC) java.sql package to query and update the database. JDBC is an API that allows java to communicate with a database server.
1 Lecture 29 More on JDBC Overview  Objectives of this lecture  JDBC and its Drivers  Connecting to Databases (Java’s Connection class)  Querying a.
1 Foundations of Software Design Lecture 27: Java Database Programming Marti Hearst Fall 2002.
JDBC Java API for Database Connectivity. Layout of this recitation Introduction to JDBC API JDBC Architecture Understanding the design of JDBC API –Classes.
JAVA JDBC JAVA JDBC Java Database Programming Lamiaa Said.
JDBC CS 122. JDBC zJava Database Connectivity zDatabase Access Interface Õprovides access to a relational database (by allowing SQL statements to be sent.
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.
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.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 8 Object Oriented Programming in Java Advanced Topics Java Database.
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.
Intro to JDBC To effectively use Java Data Base Connectivity we must understand: 1.Relational Database Management Systems (RDBMS) 2.JDBC Drivers 3.SQL.
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.
Java Utility Classes CS 21b. Some Java Utility Classes Vector Hashtable StringTokenizer * import java.util.*;
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
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.
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.
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. 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.
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.
Li Tak Sing COMPS311F. Database programming JDBC (Java Database Connectivity) Java version of ODBC (Open Database Connectivity) ODBC provides a standard.
COMP 321 Week 4. Overview Normalization Entity-Relationship Diagrams SQL JDBC/JDBC Drivers hsqldb Lab 4-1 Introduction.
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
Database Access Using JDBC BCIS 3680 Enterprise Programming.
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.
Basics of JDBC.
Basics of JDBC Session 14.
JDBC (Java Database Connectivity)
Advanced Java Session 5 New York University School of Continuing and Professional Studies.
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.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Java Database Connectivity.
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. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java program to connect to any database.
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
Lec - 14.
JDBC 15-Apr-18.
JDBC 21-Aug-18.
JDBC 15-Nov-18.
Objectives In this lesson, you will learn about:
JDBC – ODBC DRIVERS.
Java Database Connectivity
Java API for Database Connectivity
JDBC Example.
Presentation transcript:

JDBC Enterprise Systems Programming

JDBC  Java Database Connectivity  Database Access Interface provides access to a relational database (by allowing SQL statements to be sent and executed through a Java program) JDBC package: set of Java classes that facilitate this access (java.sql.*)  Comes with JDK (since 1.1)

JDBC Driver Need a driver, specific to the DB product, to mediate between JDBC and the database the driver is a Java class that needs to be loaded first Relational DBMS Java Program - load driver - establish connection - send SQL statements

JDBC-ODBC Bridge  Driver that interfaces with ODBC (Object Database Connectivity--also an access interface)  Easiest way to access databases created by Microsoft products register database as an ODBC data source use JDBC-ODBC bridge as the JDBC driver (included in JDK distribution)

Key Classes in JDBC  Connection need to create an instance of this class when establishing a connection to the database  Statement for issuing SQL statements  ResultSet (interface) a ResultSet object represents the table returned by an SQL select statement

Establishing a Connection Use the getConnection() method under the DriverManager class String argument: "jdbc:driver:name” returns a Connection object Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); // above line loads the jdbc-odbc driver String dbname = “jdbc:odbc:MyDB”; Connection c = DriverManager.getConnection(dbname);

Creating a Statement Object Execute the createStatement() method on the Connection object returns a Statement object afterwards, run methods on the Statement object to execute an SQL statement Statement s = c.createStatement();

Methods of the Statement Class  executeQuery() requires a String argument (a select statement) returns a ResultSet object  executeUpdate() requires a String argument (an insert, update, or delete statement) returns an int (row count, in most cases)

The ResultSet Interface  A ResultSet object represents the table returned by the select statement sent  Navigation/retrieval methods next(): moves to the next row (first row if called for the first time), returns false if no rows remain getXXX() methods return the value of a field for the current row

get Method Example: getInt() ResultSet rs; rs = s.executeQuery(“SELECT * FROM ORDER”); rs.next(); // gets the first row (use in a loop for multiple rows) // suppose the ORDER table has an integer field // called quantity int myvar = rs.getInt(“quantity”); // if you knew that quantity is the 2nd field in the table myvar = rs.getInt(2); Actually, this example will produce an SQL syntax error because ORDER is a reserved word in SQL. To fix, use this string instead: “SELECT * FROM [ORDER]”

Exercise  Create a Microsoft Access table insert sample rows  Add an ODBC data source use the Microsoft Access driver associate with the created database  Create a Java program use JDBC-ODBC bridge create a loop that lists all rows of the table

Summary  JDBC allows you to write Java programs that manipulate a database  A driver (often a separate product) is required that facilitates access  Key classes: Connection, Statement, and ResultSet  Other features: metadata, parameterized statements, and stored-proc invocation