A Brief Introduction to JDBC

posted on 19 Apr 2005 03:12 by somkiat

A Brief Introduction to JDBC
by Faisal Khan.

This article provides a brief introduction to JDBC. Explains what is JDBC and how it can be used to access RDBMS. Provides a brief overview of JDBC architecture.

What is JDBC?
JDBC stands for "Java DataBase Connectivity". It is an API (Application Programming Interface) which consists of a set of Java classes, interfaces and exceptions and a specification to which both JDBC driver vendors and JDBC developers (like you) adhere when developing applications.

JDBC is a very popular data access standard. RDBMS (Relational Database Management Systems) or third-party vendors develop drivers which adhere to the JDBC specification. Other developers use these drivers to develop applications which access those databases e.g. you'll use ConnectorJ JDBC driver to access MySQL database. Since the drivers adhered to JDBC specification, the JDBC application developers can replace one driver for their application with another better one without having to rewrite their application. If they had used some proprietary API provided by some RDBMS vendor, they will not have been able to change the driver and/or database without having to rewrite the complete application.

Who develops JDBC Specification?
SUN prepares and maintains the JDBC specification. Since JDBC is just a specification (suggestions for writing and using JDBC drivers), third-party vendors develop JDBC drivers adhering to this specification. JDBC developers then use these drivers to access data sources.

Why use JDBC?
JDBC is there only to help you (a Java developer) develop data access applications without having to learn and use proprietary APIs provided by different RDBMS vendors. You just have to learn JDBC and then you can be sure that you'll be able to develop data access applications which can access different RDBMS using different JDBC drivers.

JDBC Architecture
We'll divide it into 2 parts:

  • JDBC API (java.sql & javax.sql packages)
  • JDBC Driver Types

The JDBC API is available in the java.sql and javax.sql packages. Following are important JDBC classes, interfaces and exceptions in the java.sql package:

  • DriverManager - Loads JDBC drivers in memory. Can also be used to open connections to a data source.
  • Connection - Represents a connection with a data source. Is also used for creating Statement, PreparedStatement and CallableStatement objects.
  • Statement - Represents a static SQL statement. Can be used to retrieve ResultSet object/s.
  • PreparedStatement - Higher performance alternative to Statement object, represents a precompiled SQL statement.
  • CallableStatement - Represents a stored procedure. Can be used to execute stored procedures in a RDBMS which supports them.
  • ResultSet - Represents a database result set generated by using a SELECT SQL statement.
  • SQLException - An exception class which encapsulates database base access errors.

javax.sql is part of J2SE 1.4 and J2EE 1.3. It adds following features to JDBC in addition to the ones provided by java.sql package:

  • DataSource - Abstracts a data source. This object can be used in place of DriverManager to efficiently obtain data source connections (possibly using hidden connection pooling).
  • Provides built-in connection pooling.
  • XADataSource, XAConnection - Allows/supports distributed transactions.
  • RowSet - It extends ResultSet interface to add support for disconnected result sets.

JDBC Driver Types
There are 4 types of JDBC drivers. Commonest and most efficient of which are type 4 drivers. Here is the description of each of them:

  • JDBC Type 1 Driver - They are JDBC-ODBC Bridge drivers. They delegate the work of data access to ODBC API. They are the slowest of all. SUN provides a JDBC/ODBC driver implementation.
  • JDBC Type 2 Driver - They mainly use native API for data access and provide Java wrapper classes to be able to be invoked using JDBC drivers.
  • JDBC Type 3 Driver - They are written in 100% Java and use vendor independent Net-protocol to access a vendor independent remote listener. This listener in turn maps the vendor independent calls to vender dependent ones. This extra step adds complexity and decreases the data access efficiency.
  • JDBC Type 4 Driver - They are also written in 100% Java and are the most efficient among all driver types.

SUN encourages to develop and use type 4 drivers in your applications.

In this article we learned what is JDBC, why is JDBC useful and why to develop applications using JDBC.

In next set of articles we will learn how to setup a database and a JDBC driver.




salomon shoes Serena giggles. "I guess
nike mercurial it would
michael kors,sac michael kors,michael kors sac,michael kors pas cher,sac michael kors pas cher,michael kors france have
cartier been more fun
bebe dresses,bebe clothing,bebe outlet,bebe outlet online,bebe stores if I'd really been
michael kors outlet online,michael kors,kors outlet,michael kors outlet,michael kors handbags,michael kors outlet online sale,michael kors handbags clearance,michael kors purses,michaelkors.com,michael kors bags,michael kors shoes,michaelkors,cheap michael kors Stan
toms shoes,toms outlet,toms shoes outlet,tom shoes,toms wedges,cheap toms,toms.com 5."
designer handbags,handbags outlet,purses and handbags,wholesale handbags,designer bags,bags outlet,handbags wholesale,cheap purses,discount handbags,cheap handbags,handbags sale,wholesale purses,handbags and purses,designer purses Blair didn't
kobe x say anything. She'd basically
eyeglass frames,eyeglasses online,glasses frames,glasses online,eyeglasses frames,eyeglasses stores,cheap eyeglasses,cheap glasses,sunglasses for women,39 dollar glasses,cheap eyeglasses online,discount eyeglasses,cheap sunglasses,sunglasses outlet,sunglasses wholesale,wholesale sunglasses just broken
uggs outlet up
air max 90 with Nate-
marc jacobs handbags,marc jacobs,marc by marc jacobs,marc jacobs outlet again- after passing up a perfectly
toms shoes good opportunity to
levi's jeans fool
michael kors around with
cheap basketball shoes a boy who could very well
birkin bag,hermes belt,hermes handbags,hermes birkin,hermes bags,birkin bags get
reebok shoes her into Yale. Well,
nike blazer,blazer nike,nike blazer pas cher,Chaussures Nike Blazer,Nike Blazer Femme one thing
polo ralph lauren,ralph lauren outlet,ralph lauren outlet online,polo ralph lauren outlet,polo ralph lauren outlet online,ralph lauren,polo ralph,polo shirts,ralphlauren.com,polo outlet,ralph lauren polo was for sure:
chanel handbags,chanel bags,chanel sunglasses,chanel outlet,chanel purses,chanel handbags official site She wasn't about
timberland boots to
cheap eyeglasses let
guess factory Stan
wedding dresses 5
tory burch get away.
chanel handbags Serena threw
harrods london back
omega watches,omega watch,replica watches,rolex watches,replica omega watches,rolex,watches for men,watches for women,rolex watches for sale,rolex replica,rolex watch,cartier watches,rolex submariner,fake rolex,rolex replica watches,replica rolex the covers and
ugg boots,uggs outlet,ugg,uggs,ugg boots clearance,uggs on sale,uggs boots,ugg australia,ugg slippers grabbed the leather bound room service menu
cheap jerseys from beside
true religion outlet the table. "Let's order filet mignons
burberry uk and French fries and
lululemon beer
dansko shoes and watch
jimmy choo,jimmy choo shoes,jimmy choo outlet,jimmy choo handbags old
adidas movies!" She'd
roshe run always
bebe dresses been
burberry an expert
ray ban sunglasses at changing the subject. Blair scooted her feet up underneath
beats by dre,dr dre,beats headphones,dre beats,beats by dr,beats by dr dre,beats audio,dr dre beats,dre headphones,beats by dre headphones,beats by dr. dre,cheap beats her and
burberry,burberry outlet,burberry outlet online,burberry factory outlet,burberry sale,burberry handbags reached for
ray ban sunglasses the
new balance shoes TV
oakley sunglasses,cheap oakley,cheap oakley sunglasses,oakley sunglasses cheap,oakley outlet,oakley sunglasses outlet,oakley vault,oakleys,oakley.com,sunglasses outlet,cheap sunglasses,oakley prescription glasses,fake oakleys,oakley glasses,oakley store,fake oakley,oakley sale,cheap oakleys,discount oakley sunglasses remote.
burberry outlet There
new balance might
tommy hilfiger,hilfiger outlet,tommy hilfiger outlet,tommy hilfiger outlet stores,tommy hilfiger outlet stores online,tommy hilfiger bedding be an
adidas outlet Audrey Hepburn
marc jacobs movie on TCM or AMC. She
vans shoes,vans outlet,vans store,star wars vans shoes,cheap vans,vans shoes outlet,white vans,black vans,red vans,vans star wars,vans sneakers,vans shoes outlet store,vans sale,cheap vans shoes flicked
michael kors outlet online through the channels
wedding dresses,prom dresses,bridesmaid dresses,evening dresses,beach wedding dresses,cheap wedding dresses,homecoming dresses,prom dresses,wedding dresses hopefully. Aha! 'My Fair Lady'. Well, at least
jordan retro that
north face outlet was something.
cheap jordans,cheap jordan shoes,cheap jordan,cheap jordans for sale,jordans for cheap,jordan shoes,jordans,air jordan,jordan retro,jordan 11,jordan xx9,jordan 6,new jordans,air jordans,retro jordans,jordan retro 11,jordan 5,air jordan 11,jordans for sale,jordan 4,jordan 1,jordan future,jordan 3,jordan 12,michael jordan shoes,air jordan shoes,air jordan retro Serena lit a Merit Ultra Light, took
michael kors outlet,michael kors handbags,michael kors uk,michael kors,michael kors,michael kors bags a puff, and then stuck it
Ray Ban Sunglasses,Ray Ban Outlet,Ray Ban Sale,Cheap Ray Bans,Cheap Ray Ban Sunglasses,ray ban sunglasses outlet,ray ban,rayban,ray bans,ray-ban,raybans,ray ban wayfarer,ray-ban sunglasses,raybans.com,rayban sunglasses,cheap ray ban in Blair's
stuart weitzman mouth.
cheap nfl jerseys The n
nike air force she picked up
air max 95 the