For getting to know about various powerful features of Java, you need to clear your basics of JDBC API. With respect to any Java interview, JDBC questions are always available. So please see the below sections which have frequently asked JDBC interview questions and answers for freshers along with experienced Java developers.
1) What is JDBC?
Java Database Connectivity is the full-form for JDBC and it is a standard Java API for relational database communication. For connecting to the database JDBC API has interfaces connection and also performs operations like query and update. For connecting with the database, JDBC API uses JDBC drivers.
2) Explain JDBC Driver and its types?
There are classes and interfaces for enabling applications of Java in JDBC driver for interacting with a database. Here are 4 types of JDBC drivers:
Type 1 driver or JDBC-ODBC driver- Native ODBC driver is used by JDBC-ODBC bridge driver for connecting to the database. It turns JDBC method calls into the ODBC function calls.
Type 2 driver or Native-API, partly Java driver- The client-side libraries of the Native API driver is used by the database libraries. The JDBC calls are converted by the driver into database calls with the help of using native API provided by the database. It is a database related driver and once you change from one database to another there is a need to change this driver.
Type 3 driver or Network Protocol pure Java driver- Server sider middleware is used by the Network Protocol driver for converting JDBC calls into the vendor-specific database protocol.
Type 4 driver or Native-protocol, pure Java driver- In today’s world, this is the most frequently used driver. The JDBC calls are converted by the driver directly into database protocols which are specific to a vendor. There are various protocols which are proprietary and therefore the there are database vendors that have a primary source for this driver type.
3) Explain the fastest JDBC driver type?
Native Protocol or Type driver is the pure form of Java driver and is considered the fastest driver as it converts into specific vendor protocol from JDBC calls which has direct contact with the database.
4) Explain the types of Statements in JDBC
There are 3 types of JDBC statements:
Statement- For the purpose of executing a static SQL statement during runtime this is used mostly. Using Connection.createStatement() an object of statement class can be created.
Prepared Statement- For the purpose of executing same SQL statement lots of times this statement is used. In a PreparedStatement object SQL statement is precompiled and stored in a Prepared statement object. For executing this statement various times, this object is widely used.
Callable Statement- For executing SQL stored procedures or functions this statement is used and a CallableStatement object class is created using Connection.prepareCall() method.
5) Difference between Preparedstatement and Callablestatement
For executing a precompiled SQL statement multiple times, a Prepared statement is used. For executing SQL stored procedures, Callable Statement is used. There are various functions and cursors too in the process of Callable Statement executed and it extends the Prepared statement Interface.
Follow the above JDBC interview questions and answers to be a successful Java developer