JDBC is a layer of abstraction that allows users to choose between databases. JDBC allows you to write database applications in Java without having to concern yourself with the underlying details of a particular database.
There are 4 types of JDBC Drivers
Type 1: JDBC-ODBC Bridge Driver
Type 2: Native API Partly Java Driver
Type 3: Network protocol Driver
Type 4: JDBC Net pure Java Driver
The JDBC Driver provides vendor-specific implementations of the abstract classes provided by the JDBC API. Each vendors driver must provide implementations of the java.sql.Connection,Statement,PreparedStatement, CallableStatement, ResultSet and Driver.
It's a class. This class provides the static getConnection method, through which the database connection is obtained.
java.sql.Connection is an interface. The implmentation is provided by the vendor specific Driver.
java.sql.Statement,java.sql.PreparedStatement and java.sql.CallableStatement are interfaces.
CallableStatement extends PreparedStatement.
The Class.forName("") method is used to load the driver.
The Class.forName("") method can be used to load any class, not just the database vendor driver class.
Class.forName("") method throws ClassNotFoundException. This exception is thrown when the JVM is not able to find the class in the classpath.
An interface cannot be instantiated. But reference can be made to a interface. When a reference is made to interface, the refered object should have implemented all the abstract methods of the interface. In the above mentioned line, DriverManager.getConnection method returns Connection Object with implementation for all abstract methods.
int. It indicates the no of records affected by the query.
boolean. It indicates whether the query executed sucessfully or not.
Resultset is an interface.
PreparedStatements are precompiled and so performance is better.PreparedStatement objects can be reused with passing different values to the queries.
CallableStatement is used to execute Stored Procedures.
CallableStament.prepareCall().
Opening and closing of database connections is a costly(resource intensive).So a pool of database connections is obtained at start up by the application server and maintained in a pool.When there is a request for a connection from the application, the application server gives the connection from the pool and when closed by the application is returned back to the pool. Min and max size of the connection pool is configurable. This technique provides better handling of database connectivity.