Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming.

Slides:



Advertisements
Similar presentations
Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Advertisements

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)
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.
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.
CSE470 Software Engineering Fall Database Access through Java.
JDBC Java API for Database Connectivity. Layout of this recitation Introduction to JDBC API JDBC Architecture Understanding the design of JDBC API –Classes.
Objectives Describe JDBC Describe JDBC Driver Types
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.
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.
Java Database Connectivity Vijayan Sugumaran Department of DIS Oakland University.
© Wang Bin 2004 JDBC ----Java Database Connectivity.
CSE470 Software Engineering Fall Database Access through Java.
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.
What is JDBC? Java Database Connectivity (JDBC) is an API for the Java programming language that defines how a client may access a database. provides.
Database Programming in Java Corresponds with Chapter 32, 33.
© D. Wong  Indexes  JDBC  JDBC in J2EE (Java 2 Enterprise Edition)
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.
CONTROLPANEL Java.sql package This package provides the APIs for accessing and processing data which is stored in the database especially relational.
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.
JDBC – Java DataBase Connectivity. JDBC API Overview JDBC is Java API that allows the Java programmers to access database management system from Java.
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.
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.
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. Java.sql.package The java.sql package contains various interfaces and classes used by the JDBC API. This collection of interfaces and classes enable.
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.
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.
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.
Database Access Using JDBC BCIS 3680 Enterprise Programming.
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 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.
1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 8: Applications Programming for Relational Databases Instructor’s.
Introduction to JDBC Instructor: Mohamed Eltabakh 1.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Java Database Connectivity.
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.
CS320 Web and Internet Programming Database Access with JDBC Chengyu Sun California State University, Los Angeles.
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
JDBC Database Management Database connectivity
JDBC.
Introduction to Programming with Java
Chapter 16 JAVA DATABASE CONNECTIVITY
Objectives In this lesson, you will learn about:
Interacting with Database
JDBC – ODBC DRIVERS.
Java API for Database Connectivity
Presentation transcript:

Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming

2IBM Two-Tier Architecture Client connects directly to server e.g. HTTP

Advantage Simple in Design Easy to maintain and modify Communication is fast Disadvantages: Inflexible Limited Client Less secure Cost ineffective

4IBM Three-Tier Architecture Application Server sits between client and database User Interface UI Logic Business Logic Database Tables User Data DML Operations Validation Checks Database Server Layer Client Layer Application Server Layer Business Messages Network

Advantage Flexible: one part can change without affecting other Can connect to different database High performance Data integrity improve More secure Can implement proxy and firewall

Disadvantages High Maintenance High Complexity Lower network efficiency

7 Java Application Database The below given figure shows the Employee Logging System application developed in Java interacting with the Employee database using the JDBC API: EmpName Address Employee Logging System EmployeeLog Name RDBMS JDBC API Connects to

8  It can be categorized into into two layers: Java Application JDBC API Oracle DB2 SQL Server Driver JDBC Application Layer JDBC Driver Layer JDBC Architecture

9IBM JDBC Drivers Type I: “Bridge” - Type II: “Native” - Type III: “Middleware” - Type IV: “Pure” - JDBC-ODBC Bridge Driver Native-API Partly-Java Driver JDBC-Net Pure-Java Driver Native Protocol Pure-Java Driver Overview of All Drivers

10IBM Type I Drivers Use bridging technology Translates query obtained by JDBC into corresponding ODBC query, which is then handled by the ODBC driver. Almost any database for which ODBC driver is installed, can be accessed.

11IBM Disadvantage of Type-I Driver Performance overhead since the calls have to go through the JDBC overhead bridge to the ODBC driver, then to the native db connectivity interface. The ODBC driver needs to be installed on the client machine. Not good for Web

12IBM Type II Drivers Native API drivers Better performance than Type 1 since no jdbc to odbc translation is needed. Converts JDBC calls into calls to the client API for that database.

13IBM Disadvantage of Type-II Driver The vendor client library needs to be installed on the client machine. Cannot be used in internet due the client side software needed. The driver is compiled for use with the particular operating system. Not good for Web

14IBM Type III Drivers Follows a three tier communication approach. Calls middleware server, usually on database host Very flexible -- allows access to multiple databases using one driver Only need to download one driver

15IBM Disadvantage of Type-III Driver Requires database-specific coding to be done in the middle tier. An extra layer added may result in a time- bottleneck.

16IBM Type IV Drivers 100% Pure Java -- Communicate directly with a vendor’s database through socket connection Use Java networking libraries to talk directly to database engines

17IBM Disadvantage of Type-IV Driver At client side, a separate driver is needed for each database

18IBM JDBC Process 1.Loading JDBC Driver 2.Connect to Dbms 3.Create Statement object 4.Query execution 5.Process the result 6.Connection termination java.sql package required

19IBM Loading Driver User must create database and added under DSN in control panel JDBC driver must be loaded or registered before connecting to dbms Class. forName (“sun.jdbc.odbc.JdbcOdbcDriver”)

20IBM Connecting to database DriverManager class is use to make connection to database through DSN Result is stored in object of Connection class DriverManager.getConnection(“ jdbc: odbc:DSN name”) DriverManager.getConnection (“jdbc:odbc:DSN name”, String username, String password)

21IBM Create statement object Statements are used to execute sql queries Three types of statement: Statement PreparedStatement CollableStatement Connection class object use to create staement Statement objectname = connection class object.createStataemnt()

22IBM Query execution SQL queries are executed to perform operations on database like insert, select etc. It returns ResultSet class object through which database is accessed.

23IBM Process the result Different methods are use to accessed rows and columns of table. getX() method is use to obtain value of column of perticular row. getX( column index/name) X may be Int, Float, Boolean, String etc. e.g. getInt(2)

24IBM Connection termination Connection are closed using close method.

25IBM Methods of Statement class ExecuteQuery()- It used to obtain information form database. Select query is used for this method. Returntype is Object of resultset class e.g. executeQuery(“select * from tablename”)

26IBM Methods of Statement class ExecuteUpdate()- It used to perfrom operation on database. Insert, update, delete query is used for this method. Returntype is integer which represent total number of rows affected e.g. executeUpdate(“insert into tablename values”)

27IBM Methods of Statement class Execute()- It used to perform any type operation on database. Return type is Boolean If value is true then result stored in resultset object and if value is false then result stored in integer. If true execute getResultSet() and false execute getUpdateCount() method e.g. execute(“insert into tablename values”)

28IBM ResultSet This class provides method to access data generated by query in table setX is main method getRow()method use to count total rows

29IBM ResultSet Scrollable resultset will move backward or forward first() last() next() absolute (int position) relative(+- int position) Returntype of all methods are boolean To use methods other than next following constants are used ResultSet.TYPE-Scroll_SENSITIVE ResultSet.CONCUR_UPDATABLE

30IBM PreparedStatement Query precompiled ? Given on the place of value PreparedStatement objname=connectionobjname.prepareStatement(String query) Value of ? Set using setX method setX(? Position, Value) e.g. setInt(1,10)

31IBM CallableStatement Call stored procedures stored in jdbc application program It use three parameter: IN- Input data to procedure OUT- Data return by procedure INOUT- Input as well as output data

32IBM MetaData Infromation describe Database or Resultset Types: DatabaseMetaData DatabaseMetaData objname= Connectionobjname.getMetaData() ResultSetMetaData ResultSetMetaData objname= ResultSetobjname.getMetaData()

33IBM DatabaseMetaData methods getDatabaseProductVersion() getURL() getDatabaseProductName() getDriverName() getUserName()

34 IBM ResultSetMetaData methods getColumnCount() getColumnName(int position) getColumnType(int position) rt: int getTableName(int columnposition) getColumnDisplaySize(int columnposition) getColumnTypeName(int position)

35 IBM Exception SQL Exception: if query wrong then exception generated SQL Warning: Provide information about database access warning If data lost due to truncation then TruncationException is thrown