Java and Databases. JDBC Architecture Java Application JDBC API Data Base Drivers AccessSQL Server DB2InformixMySQLSybase.

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

JDBC – Java DataBase Connectivity CSE432 Object Oriented Software Engineering.
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.
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 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 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.
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:
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.
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:
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.
© 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.
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.
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.
Introduction to JDBC Michelle Lee, Ye Wu & Jeff Offutt SWE 432 Design and Implementation of Software for the Web.
JDBC  The JDBC (Java Database Connectivity) API helps a Java program to access a database in a standard way  JDBC is a specification that tells the.
JDBC – Java DataBase Connectivity. JDBC API Overview JDBC is Java API that allows the Java programmers to access database management system from Java.
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.
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.
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.
JDBC CHAPTER-2. JDBC - Java Database Connectivity. JDBC from Sun Microsystems provides API or Protocol to interact with different databases. With the.
UNIT III - JDBC JDBC Overview – JDBC implementation – Connection class – Statements - Catching Database Results, handling database Queries. Networking–
Java JDBC API. A Java API To Access almost any kind of tabular data To Access almost any kind of tabular data Trademarked (not an acronym) Trademarked.
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.
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 Chapter 1 JDBC Introduction
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.
Umair Javed©2005 Enterprise Application Development Java Database Connectivity (JDBC) JDBC1.
6-1 JAVA DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
Java and database. 3 Relational Databases A relational Database consists of a set of simple rectangular tables or relations The column headings are.
JDBC Statements The JDBC Statement, CallableStatement, and PreparedStatement interfaces define the methods and properties that enables to send SQL or PL/SQL.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java program to connect to any database.
JDBC – Java DataBase Connectivity
Interacting with Database
Lec - 14.
JDBC 15-Apr-18.
Course Outcomes of Advanced Java Programming AJP (17625, C603)
JDBC Database Management Database connectivity
JDBC 21-Aug-18.
HW#4 Making Simple BBS Using JDBC
JDBC – Java DataBase Connectivity
JDBC – Java DataBase Connectivity
JDBC 15-Nov-18.
Mr. Harish Sharma Asst. Professor Dept. of CA & IT SGRRITS Dehradun
Interacting with Database
JDBC – ODBC DRIVERS.
JAVA DATABaSE CONNECTIVITY
ODBC and JDBC.
Java API for Database Connectivity
JDBC – Java DataBase Connectivity
Java Chapter 6 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Java and Databases

JDBC Architecture Java Application JDBC API Data Base Drivers AccessSQL Server DB2InformixMySQLSybase

JDBC Driver Types Type 1 – JDBC-ODBC Driver Type 2 –Java/Native Code Driver Type 3 –JDBC Driver Type 4 –JDBC Driver

Type 1 Drivers Translate JDBC into ODBC and use Windows ODBC built in drivers ODBC must be set up on every client – driver must be physically on each machine for both java applications and applets –for server side servlets ODBC must be set up on web server driver sun.jdbc.odbc.JdbcOdbc provided by JavaSoft with JDK

Type 1 Driver (cont.) ClientJDBC- ODBC ODBCDB Vendor Library

Type 2 java/Native code Drivers Uses java classes to generate platform specific code- only understood by a specific DBMS. Disadvantage –The loss of some portability of code

Type 2 Drivers (cont.) Client JDBC Vendor Library DB

Type 3 Drivers Also referred as java protocol Convert SQL queries into JDBC formatted statement.

Type 3 Drivers (cont.) ClientJDBC Vendor Middleware DB Tier 1Tier 2 Tier 3

Type 4 Drivers Database protocol. compiles into the application, applet or servlet; doesn’t require anything to be installed on client machine, except JVM Fastest way to communicate SQL queries to the DB.

Type 4 Drivers (cont.) Client JDBCDB

JDBC Process Loading JDBC Driver Connecting to the DBMS Creating and executing statement Processing data returned by the DBMS Terminating the connection with DBMS

import java.sql.*; public class Emp { public static void main(String[] args) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:emp", "",""); Statement s = con.createStatement(); s.execute("create table employee ( emp_id number,emp_name varchar(20),emp_address varchar(30) )"); // create a table s.execute("insert into employee values(001,'ARman','Delhi')"); // insert first row into the table s.execute("insert into employee values(002,'Robert','Canada')"); // insert second row into the table s.execute("insert into employee values(003,'Ahuja','Karnal')"); // insert third row into the table s.execute("select * from employee"); // select the data from the table ResultSet rs = s.getResultSet(); // get the ResultSet that will generate from our query if (rs != null) // if rs == null, then there is no record in ResultSet to show

while ( rs.next() ) // By this line we will step through our data row-by-row { System.out.println("________________________________________" ); System.out.println("Id of the employee: " + rs.getString(1) ); System.out.println("Name of employee: " + rs.getString(2) ); System.out.println("Address of employee: " + rs.getString(3) ); System.out.println("________________________________________" ); } s.close(); // close the Statement to let the database know we're done with it con.close(); // close the Connection to let the database know we're done with it } catch (Exception err) { System.out.println("ERROR: " + err); }

Once a connection is obtained we can interact with the database. The JDBC Statement, CallableStatement, and PreparedStatement interfaces define the methods and properties that enable you to send SQL or PL/SQL commands and receive data from your database. They also define methods that help bridge data type differences between Java and SQL data types used in a database. InterfacesRecommended Use StatementUse for general-purpose access to your database. Useful when you are using static SQL statements at runtime. The Statement interface cannot accept parameters. PreparedStatementUse when you plan to use the SQL statements many times. The PreparedStatement interface accepts input parameters at runtime. CallableStatementUse when you want to access database stored procedures. The CallableStatement interface can also accept runtime input parameters.