JDBC (Java Data Base Connectivity)
JDBC (Java Data Base Connectivity)
The JDBC ( Java Database Connectivity) API defines interfaces and classes for writing database applications in Java by making database connections. Using JDBC you can send SQL, PL/SQL statements to almost any relational database. JDBC is a Java API for executing SQL statements and supports basic SQL functionality. It provides RDBMS access by allowing you to embed SQL inside Java code.
JDBC Architecture
Java application calls the JDBC library. JDBC loads a driver which talks to the database. We can change database engines without changing database code.
Functionality
JDBC allows multiple implementations to exist and be used by the same application. The API provides a mechanism for dynamically loading the correct Java packages and registering them with the JDBC Driver Manager. JDBC connections support creating and executing statements. These may be update statements such as SQL's CREATE, INSERT, UPDATE and DELETE, or they may be query statements such as SELECT
Statement
The object used for executing a static SQL statement and returning the results it produces. By default, only one ResultSet object per Statement object can be open at the same time. All execution methods in the Statement interface implicitly close a statment's current ResultSet object if an open one exists.
java.sql Interface Statement All Superinterfaces: Wrapper All Sub interfaces: CallableStatement, PreparedStatement
public interface Statementextends Wrapper
executeUpdate
int executeUpdate(String sql) throws SQLException Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement. Parameters:sql - an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement. Returns:either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing Throws:SQLException - if a database access error occurs, this method is called on a closed Statement or the given SQL statement produces a ResultSet object
PreparedStatement
An object that represents a precompiled SQL statement. A SQL statement is precompiled and stored in a PreparedStatement object. This object can then be used to efficiently execute this statement multiple times. java.sql Interface PreparedStatement All Superinterfaces: Statement, Wrapper All Known Subinterfaces: CallableStatement
executeUpdate
int executeUpdate() throws SQLException Executes the SQL statement in this PreparedStatement object, which must be an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement. Returns:either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing Throws:SQLException- if a database access error occurs; this method is called on a closed PreparedStatement or the SQL statement returns a ResultSet object
Callable Statement
The interface used to execute SQL stored procedures. The JDBC API provides a stored procedure SQL escape syntax that allows stored procedures to be called in a standard way for all RDBMSs. java.sql Interface CallableStatement All Superinterfaces: PreparedStatement, Statement, Wrapper public interface CallableStatementextends PreparedStatement
Advantage
The JDBC-ODBC Bridge allows access to almost any database, since the database's ODBC drivers are already available.
Disadvantages
1. Since the Bridge driver is not written fully in Java, Type 1 drivers are not portable. 2. A performance issue is seen as a JDBC call goes through the bridge to the ODBC driver, then to the database, and this applies even in the reverse process. They are the slowest of all driver types. 3. The client system requires the ODBC Installation to use the driver. 4. Not good for the Web.