0% found this document useful (0 votes)
6 views2 pages

API

The JDBC API, located in the java.sql package, consists primarily of abstract classes and interfaces for database connectivity in Java. Key interfaces include Driver, Connection, Statement, PreparedStatement, CallableStatement, and ResultSet, each serving specific functions for executing SQL operations and managing database connections. The DriverManager class facilitates connection management, and design patterns like Factory Method and Abstract Factory are employed to streamline object creation and management in JDBC applications.

Uploaded by

bhavikjangade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

API

The JDBC API, located in the java.sql package, consists primarily of abstract classes and interfaces for database connectivity in Java. Key interfaces include Driver, Connection, Statement, PreparedStatement, CallableStatement, and ResultSet, each serving specific functions for executing SQL operations and managing database connections. The DriverManager class facilitates connection management, and design patterns like Factory Method and Abstract Factory are employed to streamline object creation and management in JDBC applications.

Uploaded by

bhavikjangade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

2) JDBC API

*Most of the classes given in this API are pure abstract classes (interfaces)
*JDBC API is available in java.sql package

interfaces:
i) Driver
descr:
*All 4 JDBC drivers must provide one sub class of this class
*It is recommended to place driver and its all supporting sub classes must be
placed in the local system but not on remote system to avoid vast quantity of code
downloaded in to client JVM.
*This class provides one important function called connect(url, props) which return
Connection object.
*rt.jar-JdbcOdbcDriver.class
*classes111.zip-OracleDriver.class
*jdk14drv.jar-IDSDriver.class

ii) Connection:
descr:
*Functions available in this class are used to prepare 3 types of Statement
objects:
-Statement
-PreparedStatement
-CallableStatement
Methods:
- Statement createStatement()
*using this object we can execute all types SQL operations
*may not be suitable if the same SQL operation executes more than once
-PreparedStatement prepareStatement("insert into temp values(?,?,?)")
*This function is suitable to executes one SQL operation for more than once
*But not used to execute more than one SQL operation
-CallableStatement prepareCall("{call someProc(?,?)}");
*used to request functions and procedures

3) interface Statement
Descr:
*Functions available in this interface are used to execute SELECT and UPDATABLE
operations
Methods:
-int executeUpdate("insert/update/delete");
*'i' is no of rows effected
-ResultSet executeQuery("select")
*Is a pointer for accessing data retrived into database
-boolean execute("CRUD")
*using this function we can execute all SQL operations

4) interface PreparedStatement
Descr:
*Functions available in this class are used to substitute IN parameter values as
shown below:
-setInt(1, 100);
-setString(2, "ABC");
-setDouble(3, 1000.00);

5) interface CallableStatement
Descr:
To pass IN parameters, functions derived from super class are used and only
getXXX() are implemented in this class to access OUT parameter values
-getInt(1)
6) interface ResultSet
Descr:
*Pointer for collection of records retrived from the database into database buffer.
*Allows developer to read records in serial manner
*Doesnot support rereading the data
*No updations are allowed on the data
*Can't be serialized

classes:
----------
i) class DriverManager
/*
Driver d=new JdbcOdbcDriver();
Connection con=d.connect("jdbc:odbc:OracleDSN", null);

Driver d=new OracleDriver();


Connection con=d.connect("jdbc:oracle:oci8:@tnsname", null);

// Load driver class


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con=DriverManager.getConnection("jdbc:odbc:mydsn");
The benifit of writing program as said above is to avoid creating new instance of
driver class directly in the program that inturns avoids us modifying and
recompling the program again and again as oftenly we want to change drivers.

Factory Method:
*FactoryMethod is an OO design pattern (a solution for repeatedly occuring problems
in OO systems).
*Hides the complexity behind constructing objects but as a result to request they
returns object to client
ex1: Button b=tk.createButton()
ex2: Connection con=DriverManager.getConnection()

AbstractFactory
*Class which contains collection of FactoryMethods is called as AbstractFactory
*/

You might also like