JDBC Interview Questions
Here is a collection of most of the interview questions in JDBC.
Explain what do you mean by JDBC?
Short for Java Database Connectivity, a Java API that enables Java programs
to execute SQL statements. This allows Java programs to interact with any SQL-compliant
database. Since nearly all relational database management systems (DBMSs) support SQL, and
because Java itself runs on most platforms, JDBC makes it possible to write a single database
application that can run on different platforms and interact with different DBMSs.
JDBC is similar to ODBC, but is designed specifically for Java programs,
whereas ODBC is language-independent
What are the components that constitute JDBC ?
JDBC Components include connection Pools, Data Sources, and MultiPools
How to you load the drivers in JDBC?
Class.forName() method is used in JDBC to load the JDBC drivers
What do you mean by batch updates ?
if you want to execute a set of statements, i.e. SQL statements at a time
then we use batch update statement.
Explain how you can establish a connection ?
Connection con = DriverManager.getConnection(url,”myLogin”,
What are the different types of statements in JDBC ?
java.sql.Statement – Top most interface which provides basic methods useful
for executing SELECT, INSERT, UPDATE and DELETE SQL statements.
java.sql.PreparedStatement – An enhanced verion of java.sql.Statement which
allows precompiled queries with parameters. It is more efficient to use
java.sql.PreparedStatement if you have to specify parameters to your SQL queries.
java.sql.CallableStatement – Allows you to execute stored procedures within
a RDBMS which supports stored procedures (MySQL doesn’t support stored procedures at the
Have you used prepared statements? Where have you used prepared statements ?
Yes. If you want to execute a Statement object many times, it will normally
reduce execution time to use a PreparedStatement object instead.
The main feature of a PreparedStatement object is that, unlike a Statement
object, it is given an SQL statement when it is created. The advantage to this is that in most
cases, this SQL statement will be sent to the DBMS right away, where it will be compiled. As a
result, the PreparedStatement object contains not just an SQL statement, but an SQL statement
that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can
just run the PreparedStatement ‘s SQL statement without having to compile it first.
Although PreparedStatement objects can be used for SQL statements with no
parameters, you will probably use them most often for SQL statements that take parameters. The
advantage of using SQL statements that take parameters is that you can use the same statement
and supply it with different values each time you execute it.
- What is JDBC
- JDBC Interview Questions