Here is a collection of most of the interview questions in 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
JDBC Components include connection Pools, Data Sources, and MultiPools
Class.forName() method is used in JDBC to load the JDBC drivers
if you want to execute a set of statements, i.e. SQL statements at a time
then we use batch update statement.
Connection con = DriverManager.getConnection(url,”myLogin”,
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
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.