JDBC CS 122. JDBC zJava Database Connectivity zDatabase Access Interface Õprovides access to a relational database (by allowing SQL statements to be sent.

Slides:



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

Murach’s Java SE 6, C21© 2007, Mike Murach & Associates, Inc.Slide 1.
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.
JDBC Overview Autumn 2001 Lecturer: C. DeJong. Relational Databases widespread use used via SQL (Structured Query Language) freely available powerful.
Java Database Connectivity By: Abe Marji CS616. Agenda 1.Quick Review of Databases 2.What is SQL? 3.What is JDBC? 4.Advanced Functions of JDBC 5.Summary.
1 Lecture 29 More on JDBC Overview  Objectives of this lecture  JDBC and its Drivers  Connecting to Databases (Java’s Connection class)  Querying a.
EmbeddedSQL: 1 Impedance Mismatch Problem Problem : How to connect SQL statements with conventional programming languages Different models of language.
Java database Programming JDBC Trademarked name of a Java API that supports Java programs that access relational databases Stand for Java DataBase Connectivity.
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 / 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.
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.
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.
Java Utility Classes CS 21b. Some Java Utility Classes Vector Hashtable StringTokenizer * import java.util.*;
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,
 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.
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.
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.
Copyright © 2002 ProsoftTraining. All rights reserved. Building Database Client Applications Using JDBC 2.0.
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.
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.
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.
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)
JAVA DATABASE OOP Praktek dengan Java Miswar,S.st Sumber : Eddy Muntina Dharma,ST,MT.
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.
1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 8: Applications Programming for Relational Databases Instructor’s.
Umair Javed©2005 Enterprise Application Development Java Database Connectivity (JDBC) JDBC1.
© 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.
Objectives In this lesson, you will learn about:
JDBC – ODBC DRIVERS.
Java Database Connectivity
Java API for Database Connectivity
JDBC Example.
Presentation transcript:

JDBC CS 122

JDBC zJava Database Connectivity zDatabase 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.*) zComes 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 zDriver that interfaces with ODBC (Object Database Connectivity--also an access interface) zEasiest 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 1.2 distribution)

Key Classes in JDBC zConnection Õneed to create an instance of this class when establishing a connection to the database zStatement Õfor issuing SQL statements zResultSet (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 = Driver.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 zexecuteQuery() Õrequires a String argument (a select statement) Õreturns a ResultSet object zexecuteUpdate() Õrequires a String argument (an insert, update, or delete statement) Õreturns an int (row count, in most cases)

The ResultSet Interface zA ResultSet object represents the table returned by the select statement sent zNavigation/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 Orders”); rs.next(); // gets the first row // suppose the Orders 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);

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

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