Page 1 :
Interacting with Database, , a, |, |, |, , 2, , |, , , , , , , , , , , , , , , , , , ResultSet Interface, The essential JDBC Program., , , , SEE, Syllabus Topic : Introduction to JDBC, ODBC, , 5.1 __ Introduction to JDBC, ODBC, , , , Q.5.1.1 Write note on JDBC API., , (Ref. Sec. 5.1) (Likely Ques), , , , , , , , — Programming languages like Java are used to develop, customized software. Every software or application has, its own data to be stored permanently., , Programming languages cannot store data permanently., For this purpose we have to use the Database, Management System. The DBMS Plays a significant, role in storing and managing data,, , In an application we Store data in DBMS and for, operations like insertion, modification or deletion we, write code in Programming languages i.e, software is, usually created with the help of bo, , th Programming, language and Database,, , When the application is executed, the client or user, interacts with interface of application vy}, , hich is created, in the programming language., , — The database always remains backside and do not come, in front of the user., , i ier models, Types of JDBC Drivers, p,j,.,, , ‘eduction to JDBC, OD! i : Two tier and three tier ; a, , i BC, JDBC Architecture : Two ; i :, , be sce eS ae Manager class : Connection Interfacen statement Interface, Prepared Stateme: terface, inte :, , , , , , , , Hence the database is known as backend while, , programming language is termed as frontend,, , API : An Application Programming Interface (API), is a set of subroutine definitions, communication, , protocols, and tools for building software., , In general term, it is a set of clearly defined methods of, , communication among various components., , A good API makes it easier to develop a computer, program by Providing all the building blocks, which are, then put together by the programmer., , Java Database Connectivity (JDBC) is a, Application Programming Interface (API) for the, , Programming language Java, which defines how #, client may access a database,, , Mis a Java-based data access technology used f, database Connectivity,, , It is part of the Java Standard Edition platform, from, Oracle Corporation,, , Tt provides methods to query and update data in #, database, and is oriented towards relational databases:, , PBC AEE tbe 86 arcee virtually any data soure®, from Telational databases to Spreadsheets.
Page 2 :
Interacting with Database, , , , , , JDBC API is comprised of two packages :, , _ whe, , javax.sql, , javasal 2., , Database, , , , , , ¥ Fig. 5.1.1 : JDBC API, 3C API performs following tasks :, , , , Establish connection with database., , Execute queries and update statements to the, trieve the result received from the database., , JDBC, ODBC API was the most frequently, API to connect as well as execute queries, , , , problem with ODBC API was that it uses, sr which is written in C programming, enct not platform independent and secure),, , Java defines its own API (known as, , , , The JDBC driver gives out the connection to the, database and implements the protocol for transferring, , the query and result between client and database., , Working (process) of JDBC Drivers, , Request is received by the JDBC drivers from the, client, As the request format is not understandable to, , database, the drivers convert it into to necessary, database format., , The converted request is then submitted to database., Response is received by the JDBC drivers from the, database. As the response format is not understandable, to java application, the drivers convert it into to, necessary java data format. :, , The converted response is then submitted to java, application., , JDBC technology drivers Bes inte, categories :
Page 3 :
& Adv. Java Programming (MSBTE-Sem 5-Comp/IT) _5-3, , running. Also, use of this driver leads to other, installation dependencies; for example, ODBC must be, installed on the computer having the driver and the, database must support an ODBC driver., , — The use of this driver is discouraged if the alternative of, a pure-Java driver is available., , — The other implication is that any application using a, type 1 driver is non-portable given the binding between, the driver and platform., , - This technology isn't suitable for a high-transaction, environment. Type 1 drivers also don't support the, , complete Java command set and are limited by the, functionality of the ODBC driver., , — Sun (now Oracle) provided a JDBC-ODBC Bridge, driver: sun.jdbc.odbc.JdbcOdbeDriver., , — This driver is written in native code and not Java, and is, closed source., , JDBC-ODBC Bridge Driver, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Fig. 5.1.3 : JDBC-ODBC Bridge Driver, @ Advantage, , Almost any database for which an ODBC driver is, installed can be accessed, and data can be Tettieved., , Tech-Neo Publications scree Where Authors inspire innovation, , , , or, , Interacti, , Disadvantages, , Performance overhead since the cal], through the JDBC (java database conr, , to the ODBC (open database connectj vity, to the native database connectivity inter, be slower than other types of drivers)., , The ODBC driver needs to be installed o,, machine., , Not suitable for applets, because the Opp,, needs to be installed on the client., , Specific ODBC drivers are not always avail,, , , , platforms; hence, portability of this driver is |, , , , 2. Type 2: Native-API driver, , The JDBC type 2 driver, also known as the Native-Ap|, driver, is a database driver implementation that uses the, client-side libraries of the database., , The driver converts JDBC method calls into native Calls, of the database API., , For example : Oracle OCI driver is a type 2 driver., , Native-API Driver
Page 4 :
‘Adv. Java Programming (MSBTE-Sem 5-Comp/IT), , 5-4, , Interacting with Database, , , , a advantage, , As there js no implementation of JDBC-ODBC bridge,, , 4 itmay pe considerably faster than a Type 1 driver,, , pisadvantages, , The vendor client library needs to be installed on the, client machine., , 9, Not all databases have a client-side library. This driver, js platform dependent. This driver supports all Java, applications except applets., , ) 3. Type3: Network-Protocol driver, (middleware driver), , — The JDBC type 3 driver, also known as the Pure Java, driver for database middleware, is a database driver, implementation which makes use of a middle tier, between the calling program and the database., , - The middle-tier (application server) converts JDBC, calls directly or indirectly into a vendor-specific, database protocol., , = The type 3 driver is written entirely in Java., , - The same client-side JDBC driver may be used for, multiple databases. It depends on the number of, databases the middleware has been configured to, support., , The type 3 driver is platform-independent as the, , platform-related differences are taken care of by the, middleware., , Also, making use of the middleware provides additional, advantages of security and firewall access., Functions, , Sends JDBC API calls to a middle-tier net server that, "anslates the calls into the DBMS-specific network, , Protocol. The translated calls are then sent to a, Particular DBMS., , Follows a three-tier communication approach., , Can interface to multiple databases — Not vendor, , , , r, , SS SSS ee, , , , Calling Java Application, , JDBC API, , JDBC Driver Manager, , , , , , , , , , , , , , Network -Protocol Driver, (Type 3 Driver), , , , , , , , , , , , , , , , , , Middleware, (Application server), , , , , , , , , , , , Different database vendors, , , , Fig. 5.1.5 : Network-Protocol Driver, , The JDBC Client driver written in java communicates, , with a middleware-net-server using a database, independent protocol, and then this net server translates, , this request into database commands for that database., , Thus the client driver to middleware communication is, database independent., , Advantages, , Since the communication between client and the, middleware server is database independent, there is no, need for the database vendor library on the client. The, client need not be changed for a new database., , The middleware server can provide typical middleware, services like caching (of connections, query results,, etc.), load balancing, logging, and auditing., , A single driver can handle any database, provided the, middleware supports it. e.g. : IDA Server., , Disadvantages, , Requires database-specific coding to be done in the, middle tier., , , , ;, “Ne Pablcaions oa. Where Authors inspire iamoation, , , , ~_-A SACHIN SHAH Venture
Page 5 :
| Adv. Java Programming (MSBTE-Sem 5-Comp/IT), , , , 2, The middle ware layer added may result in additional, latency, but is typically overcome by using better, middleware services., , > 4. Type4: Database-Protocol driver, , (Pure Java driver), , — The JDBC type 4 driver, also known as the Direct to, Database Pure Java Driver,, implementation that converts JDBC calls directly into a, vendor-specific database protocol., , is a database driver, , — Written completely in Java, type 4 drivers are hence, platform independent., , — They installed inside the Java Virtual Machine of the, client. This provides better performance than the type 1, and type 2 drivers as it does not have the overhead of, conversion of calls into ODBC or database API calls., , — Unlike the type 3 drivers, it does not need associated, software to work. i, , — As the database protocol is vendor specific, the JDBC, , . client requires separate drivers, usually vendor, , : supplied, to connect to different types of databases., , , , , , , , , , , , , , , , , , , Fig. 5.1.6 : Database-Prot, @ Advantages, Ny Conigheey implemented in, independence,, Tech-Neo Publications Bes Wore duos teas a, , 5.2.1, , , , , , 2. These drivers do not translate the x, , intermediary format (such as ODBC), , 3. The client application connects directly, server. No translation or middleware |,,,, , improving performance., , 4. The JVM can manage all aspects of the ;, database connection; this can facilitate, , , , , , @ Disadvantage, , 1. Drivers are database specific, as different q,, , da, , , , , yendors use widely different (and usually proprie, network protocols. \, , Syllabus Topic : JDBC Architecture, 5.2 JDBC Architecture, The JDBC API supports both two-tier and three-ey, processing models for database access., ~_ Syllabus Topic : Two Tier Model, , JDBC Two Tier Model