DEPTT. OF COMP. SC & APPLICATIONS

Slides:



Advertisements
Similar presentations
Connecting to Databases. connecting to DB DB server typically a standalone application Server runs on localhost for smaller sites –i.e. Same machine as.
Advertisements

Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Copyright  Oracle Corporation, All rights reserved. 2 Java and Databases: An Overview.
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)
Distributed Application Development B. Ramamurthy.
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
DT228/3 Web Development Databases. Database Almost all web application on the net access a database e.g. shopping sites, message boards, search engines.
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. In This Class We Will Cover: What SQL is What ODBC is What JDBC is JDBC basics Introduction to advanced JDBC topics.
1 Foundations of Software Design Lecture 27: Java Database Programming Marti Hearst Fall 2002.
JDBC / ODBC JDBC is the java API that facilitate interaction of a java application with the DBMS. FIRST APPROACH:
Dale Roberts 8/24/ Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
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.
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.
© 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.
Database Programming in Java Corresponds with Chapter 32, 33.
JAVA Database Access. JDBC The Java Database Connectivity (JDBC) API is the industry standard for database- independent connectivity between the Java.
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,
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 and Databases. RHS – SOC 2 JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
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.
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.
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.
12/6/2015B.Ramamurthy1 Java Database Connectivity B.Ramamurthy.
JDBC
Copyright © Curt Hill Connectivity Communicating with the Database.
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 Chapter 1 JDBC Introduction
Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming.
JDBC Java and Databases. SWC – JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
In the Name Of Almighty Allah. Java Application Connection To Mysql Created by Hasibullah (Sahibzada) Kabul Computer Science Faculty Afghanistan.
Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL.
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. Database is used to store data permanently. These days almost all Applications needs database to store its data persistently. Below are the most.
Database: JDBC Overview
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
ODBC, OCCI and JDBC overview
JDBC Database Management Database connectivity
Web Technologies IT230 Dr Mohamed Habib.
Database JDBC Overview CS Programming Languages for Web Applications
Advanced Web Automation Using Selenium
JDBC.
Introduction to Programming with Java
Objectives In this lesson, you will learn about:
Mr. Harish Sharma Asst. Professor Dept. of CA & IT SGRRITS Dehradun
Interacting with Database
JDBC – ODBC DRIVERS.
Java Database Connectivity
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
JAVA DATABaSE CONNECTIVITY
ODBC and JDBC.
Java API for Database Connectivity
CS3220 Web and Internet Programming Database Access with JDBC
CS3220 Web and Internet Programming Database Access with JDBC
Presentation transcript:

DEPTT. OF COMP. SC & APPLICATIONS MCA-401: ADVANCE JAVA PREPARED BY : NAVEEN NAGPAL (SENIOR ASSISTANT PROFESSOR) DEPTT. OF COMP. SC & APPLICATIONS AUTHOR: NAVEEN NAGPAL

DEPTT. OF COMP. SC & APPLICATIONS Accessing a DataBase Almost all the web applications that we see on the Internet access a database. A specialized language called Structured Query Language (SQL) is used to access the data. SQL is an ANSI standard and is supported by all major database vendors. To help programmers write code that's portable between database engines, the standard Java libraries include an API called the Java Database Connectivity (JDBC) API. JDBC defines a set of classes that can execute SQL statements the same way in any relational database. DEPTT. OF COMP. SC & APPLICATIONS

Accessing a Database from a JSP Page JSP Standard Tag Library (JSTL) includes a number of actions for database access to make it easy to develop simple database-driven JSP applications. The actions provide the following features: Using a connection pool for better performance and scalability Supporting queries, updates, and inserts. Handling the most common data-type conversions. Supporting a combination of database operations in one transaction DEPTT. OF COMP. SC & APPLICATIONS

The DataSource Interface and JDBC Drivers JSP gets access to the database through an instance of a JDBC interface named javax.sql.DataSource. The DataSource interface is part of the Java 2 Standard Edition (J2SE) 1.4, and for prior versions of the J2SE, it's available in the JDBC 2.0 Optional Package. To access a database, a connection to the database must first be established. Opening a database connection is very time-consuming. A nice thing with a DataSource is that it can represent something called a connection pool. When a database action needs a connection, it gets it from the pool through the DataSourceobject and uses it to execute one or more SQL statements DEPTT. OF COMP. SC & APPLICATIONS

DEPTT. OF COMP. SC & APPLICATIONS JDBC In addition to the DataSource, the JDBC API contains other classes and interfaces that allow a Java application to process SQL statements in a database-independent way. For each specific database engine, an implementation of the interfaces defined by the JDBC API translates the generic calls to a format understood by the engine. This implementation is called a JDBC driver DEPTT. OF COMP. SC & APPLICATIONS

DEPTT. OF COMP. SC & APPLICATIONS JDBC CONTI… According to Sun Microsystems, JDBC is not an acronym. In particular, it does not stand for Java Database Connectivity. JDBC is an application programming interface between Java programs and database management systems. Like Oracle’s Oracle Call Interface(OCI) or Microsoft’s Open Database Connectivity (ODBC), JDBC is a call-level interface. DEPTT. OF COMP. SC & APPLICATIONS

DEPTT. OF COMP. SC & APPLICATIONS JDBC CONTI… The great advantage of JDBC is it provides a standard interface to all database management systems. JDBC queries that work on an Oracle database require little or no changes to work with DB2, or SQL Server, or any other database. JDBC also eases the transition from legacy systems to Web-enabled applications. Embedded SQL products, which have been around since the early 1980s, for the most part use SQL statements and operations that can be duplicated by JDBC calls DEPTT. OF COMP. SC & APPLICATIONS

DEPTT. OF COMP. SC & APPLICATIONS Basic JDBC Operations 1. Load a JDBC driver for your DBMS. This typically involves only a ClassforName() statement specifying the driver class name. 2. Use that driver to open a connection to a particular database. This is done with a call to a static getConnection(url) method to the DriverManager class. The url argument is in a specific form that indicates the driver type and the data source to use. 3. Issue SQL statements through the connection. Once the connection is established, it can be used to create Statement objects through which SQL commands can be made. 4. Process result sets returned by the SQL operations. The ResultSet interface provides methods to step through each row and get the values of each column. DEPTT. OF COMP. SC & APPLICATIONS

DEPTT. OF COMP. SC & APPLICATIONS JDBC WORKING DEPTT. OF COMP. SC & APPLICATIONS

Essential JDBC Classes The JDBC interface is contained in the java.sql and javax.sql packages. It consists mainly of interfaces rather than concrete classes because each vendor’s implementation is specific to their particular database protocol A smaller subset of these is more commonly used, as outlined in the following: DEPTT. OF COMP. SC & APPLICATIONS

DEPTT. OF COMP. SC & APPLICATIONS Connection : An active link to a database through which a Java program can read and write data, as well as explore the database structure and capabilities. A Connection object is created either by a call to DriverManager.get Connection() or DataSource.getConnection(), in JDBC 2.0. DEPTT. OF COMP. SC & APPLICATIONS

DEPTT. OF COMP. SC & APPLICATIONS Statement : An object that allows SQL statements to be sent through a connection and retrieves the result sets and update counts they produce. ResultSet :An ordered set of table rows produced by an SQL query or a call to certain metadata functions. A ResultSet is most often encountered as the return value of a Statement.executeQuery(sqlstring)method call DEPTT. OF COMP. SC & APPLICATIONS

DEPTT. OF COMP. SC & APPLICATIONS DriverManager : An interface that registers JDBC drivers and supplies connections that can handle specific JDBC URLs. The only method commonly used is the staticDriverManager.getConnection(),in one of its three forms, which returns an activeConnectionobject bound to the specified JDBC URL. DEPTT. OF COMP. SC & APPLICATIONS

DEPTT. OF COMP. SC & APPLICATIONS SQLException : The base exception class used by the JDBC API.SQLExceptionhas methods that can supply theSQLStatevalue any vendor-specific error code. It can also be linked to anotherSQLException if more than one exception occurred. DEPTT. OF COMP. SC & APPLICATIONS

DEPTT. OF COMP. SC & APPLICATIONS JDBC DRIVERS To insulate programs from the specifics of particular database protocols, JDBC uses a middle layer composed of DriverManager class and one or more JDBC drivers. A driver is Java class, usually supplied by the database vendor, which implements the java.sql.Driver interface. The primary function of the driver is to connect to a database and return a java.sql.Connection object. DEPTT. OF COMP. SC & APPLICATIONS

DEPTT. OF COMP. SC & APPLICATIONS Driver Types Type 1—JDBC-ODBC bridge Drivers of this type connect to databases through an intermediate ODBC driver. Several drawbacks are involved with this approach, so Sun describes it as being experimental and appropriate for use only where no other driver is available. Both Microsoft and Sun provide type 1 drivers. Type 2—Native API, partly Java Similar to a JDBC-ODBC bridge, type 2 drivers use native methods to call vendor-specific API functions. These drivers are also subject to the same limitations as the JDBC-ODBC bridge, in that they require native library files to be installed on client systems, which must be configured to use them. Type 3—Pure Java to database middleware Type 3 drivers communicate using a network protocol to a middleware server, which, in turn, communicates to one or more database management systems. Type 4—Pure Java direct to database Drivers of this type call directly into the native protocol used by the database management system. DEPTT. OF COMP. SC & APPLICATIONS

DEPTT. OF COMP. SC & APPLICATIONS

DEPTT. OF COMP. SC & APPLICATIONS JDBC-ODBC Bridge the JDBC-ODBC bridge driver is limited to the capabilities of the underlying ODBC driver, which is single threaded and may, therefore, perform poorly under a heavy load. It requires native code library JdbcOdbc.dll to be installed on the client system. the JDBC-ODBC bridge driver requires an ODBC data source to be configured DEPTT. OF COMP. SC & APPLICATIONS