가장 많이 묻는 면접 질문과 답변 & 온라인 테스트
면접 준비, 온라인 테스트, 튜토리얼, 라이브 연습을 위한 학습 플랫폼

집중 학습 경로, 모의고사, 면접 준비 콘텐츠로 실력을 키우세요.

WithoutBook은 주제별 면접 질문, 온라인 연습 테스트, 튜토리얼, 비교 가이드를 하나의 반응형 학습 공간으로 제공합니다.

Prepare Interview

모의 시험

홈페이지로 설정

이 페이지 북마크

이메일 주소 구독
/ 면접 주제 / JDBC
WithoutBook LIVE Mock Interviews JDBC Related interview subjects: 39

Interview Questions and Answers

Know the top JDBC interview questions and answers for freshers and experienced candidates to prepare for job interviews.

Total 27 questions Interview Questions and Answers

The Best LIVE Mock Interview - You should go through before interview

Know the top JDBC interview questions and answers for freshers and experienced candidates to prepare for job interviews.

Interview Questions and Answers

Search a question to view the answer.

Freshers / Beginner level questions & answers

Ques 1

What is JDBC? Describe the steps needed to execute a SQL query using JDBC.

We can connect to databases from java using JDBC. It stands for Java DataBase Connectivity.
Here are the steps:
  1. Register the jdbc driver with the driver manager
  2. Establish jdbc connection
  3. Execute an sql statement
  4. Process the results
  5. Close the connection
Before doing these do import java.sql.*

JDBC is java based API for accessing data from the relational databases. JDBC provides a set of classes and interfaces for doing various database operations. The steps are:
  • Register/load the jdbc driver with the driver manager.
  • Establish the connection thru DriverManager.getConnection();
  • Fire a SQL thru conn.executeStatement();
  • Fetch the results in a result set.
  • Process the results.
  • Close statement/result set and connection object.
복습용 저장

복습용 저장

이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.

내 학습 라이브러리 열기
도움이 되었나요?
Add Comment View Comments
Ques 2

How many different types of JDBC drivers are present? Discuss them.

There are four JDBC driver types.
Type 1: JDBC-ODBC Bridge plus ODBC Driver:
The first type of JDBC driver is the JDBC-ODBC Bridge. It is a driver that provides JDBC access to databases through ODBC drivers. The ODBC driver must be configured on the client for the bridge to work. This driver type is commonly used for prototyping or when there is no JDBC driver available for a particular DBMS.
Type 2: Native-API partly-Java Driver:
The Native to API driver converts JDBC commands to DBMS-specific native calls. This is much like the restriction of Type 1 drivers. The client must have some binary code loaded on its machine. These drivers do have an advantage over Type 1 d'rivers because they interface directly with the database.
Type 3: JDBC-Net Pure Java Driver:
The JDBC-Net drivers are a three-tier solution. This type of driver translates JDBC calls into a database-independent network protocol that is sent to a middleware server. This server then translates this DBMS-independent protocol into a DBMS-specific protocol, which is sent to a particular database. The results are then routed back through the middleware server and sent back to the client. This type of solution makes it possible to implement a pure Java client. It also makes it possible to swap databases without affecting the client.
Type 4: Native-Protocol Pure Java Driver:
These are pure Java drivers that communicate directly with the vendor's database. They do this by converting JDBC commands directly into the database engine's native protocol. This driver has no additional translation or middleware layer, which improves performance tremendously.
What does the "static" keyword mean in front of a variable or a method or a class?
static variable:
- Means a class level variable
static method:
-Does not have "this". It is not allowed to access the not static members of the class.
can be invoked enev before a single instance of a class is created.
eg: main
static class:
No such thing.
static free floating block:
It is executed at the time the class is loaded. There can be multiple such blocks. This may be useful to load native libraries when using native methods.
eg:
native void doThis(){
static{
System.loadLibrary("myLibrary.lib");
}
복습용 저장

복습용 저장

이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.

내 학습 라이브러리 열기
도움이 되었나요?
Add Comment View Comments
Ques 3

What are the different driver types available in JDBC?

  1. A JDBC-ODBC bridge
  2. A native-API partly Java technology-enabled driver
  3. A net-protocol fully Java technology-enabled driver
  4. A native-protocol fully Java technology-enabled driver
복습용 저장

복습용 저장

이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.

내 학습 라이브러리 열기
도움이 되었나요?
Add Comment View Comments
Ques 4

How can you load the drivers?

Loading the driver or drivers you want to use is very simple and involves just one line of code. If, for example, you want to use the JDBC-ODBC Bridge driver, the following code will load it:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Your driver documentation will give you the class name to use. For instance, if the class name is jdbc.DriverXYZ, you would load the driver with the following line of code:
Class.forName("jdbc.DriverXYZ");
복습용 저장

복습용 저장

이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.

내 학습 라이브러리 열기
도움이 되었나요?
Add Comment View Comments
Ques 5

What will Class.forName do while loading drivers?

It is used to create an instance of a driver and register it with the DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS.
복습용 저장

복습용 저장

이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.

내 학습 라이브러리 열기
도움이 되었나요?
Add Comment View Comments
Ques 6

How can you make the connection?

To establish a connection you need to have the appropriate driver connect to the DBMS.
The following line of code illustrates the general idea:
String url = "jdbc:odbc:WithoutBook";
Connection con = DriverManager.getConnection(url, "Username", "Password");
복습용 저장

복습용 저장

이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.

내 학습 라이브러리 열기
도움이 되었나요?
Add Comment View Comments
Ques 7

How can you create JDBC statements and what are they?

A Statement object is what sends your SQL statement to the DBMS. You simply create a Statement object and then execute it, supplying the appropriate execute method with the SQL statement you want to send.

For a SELECT statement, the method to use is executeQuery. For statements that create or modify tables, the method to use is executeUpdate. It takes an instance of an active connection to create a Statement object.
In the following example, we use our Connection object con to create the Statement object:
Statement stmt = con.createStatement();
복습용 저장

복습용 저장

이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.

내 학습 라이브러리 열기
도움이 되었나요?
Add Comment View Comments
Ques 8

How can you retrieve data from the ResultSet?

JDBC returns results in a ResultSet object, so we need to declare an instance of the class ResultSet to hold our results. The following code demonstrates declaring the ResultSet object:
ResultSet rs = stmt.executeQuery("SELECT NAME,SAL FROM EMPLOYEE");
String s = rs.getString("NAME");

The method getString is invoked on the ResultSet object (rs), so getString() will retrieve (get) the value stored in the column NAME in the current row of rs. Note: rs is ResultSet variable name here.
복습용 저장

복습용 저장

이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.

내 학습 라이브러리 열기
도움이 되었나요?
Add Comment View Comments
Ques 10

How can you use PreparedStatement?

This special type of statement is derived from class Statement. If you need a Statement object to execute many times, it will normally make sense to use a PreparedStatement object instead. 

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.
PreparedStatement updateSales = con.prepareStatement("UPDATE EMPLOYEE SET SAL=? WHERE EMP_ID=?");
복습용 저장

복습용 저장

이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.

내 학습 라이브러리 열기
도움이 되었나요?
Add Comment View Comments
Ques 11

What does setAutoCommit do?

When a connection is created, it is in auto-commit mode. This means that each individual SQL statement is treated as a transaction and will be automatically committed right after it is executed. The way to allow two or more statements to be grouped into a transaction is to disable auto-commit mode:
con.setAutoCommit(false);

Once auto-commit mode is disabled, no SQL statements will be committed until you call the method commit explicitly.

con.setAutoCommit(false);
PreparedStatement updateSales =
con.prepareStatement( "UPDATE EMPLOYEE SET SAL = ? WHERE EMP_NAME LIKE ?");
updateSales.setInt(1, 50000); updateSales.setString(2, "Arindam");
updateSales.executeUpdate();
PreparedStatement updateTotal =
con.prepareStatement("UPDATE EMPLOYEE SET TOTAL = TOTAL + ? WHERE EMP_NAME LIKE ?");
updateTotal.setInt(1, 50000);
updateTotal.setString(2, "Arindam");
updateTotal.executeUpdate();
con.commit();
con.setAutoCommit(true);
복습용 저장

복습용 저장

이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.

내 학습 라이브러리 열기
도움이 되었나요?
Add Comment View Comments
Ques 12

How do you call a stored procedure from JDBC?

The first step is to create a CallableStatement object. As with Statement an and PreparedStatement objects, this is done with an open
Connection object. A CallableStatement object contains a call to a stored procedure.
CallableStatement cs = con.prepareCall("{call SHOW_EMPLOYEES}");
ResultSet rs = cs.executeQuery();
복습용 저장

복습용 저장

이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.

내 학습 라이브러리 열기
도움이 되었나요?
Add Comment View Comments
Ques 15

What are the different JDB drivers available?

There are mainly four type of JDBC drivers available. They are:

Type 1 : JDBC-ODBC Bridge Driver - A JDBC-ODBC bridge provides JDBC API access via one or more ODBC drivers. Note that some ODBC native code and in many cases native database client code must be loaded on each client machine that uses this type of driver. Hence, this kind of driver is generally most appropriate when automatic installation and downloading of a Java technology application is not important. For information on the JDBC-ODBC bridge driver provided by Sun.

Type 2: Native API Partly Java Driver- A native-API partly Java technology-enabled driver converts JDBC calls into calls on the client API for Oracle, Sybase, Informix, DB2, or other DBMS. Note that, like the bridge driver, this style of driver requires that some binary code be loaded on each client machine.

Type 3: Network protocol Driver- A net-protocol fully Java technology-enabled driver translates JDBC API calls into a DBMS-independent net protocol which is then translated to a DBMS protocol by a server. This net server middleware is able to connect all of its Java technology-based clients to many different databases. The specific protocol used depends on the vendor. In general, this is the most flexible JDBC API alternative. It is likely that all vendors of this solution will provide products suitable for Intranet use. In order for these products to also support Internet access they must handle the additional requirements for security, access through firewalls, etc., that the Web imposes. Several vendors are adding JDBC technology-based drivers to their existing database middleware products.

Type 4: JDBC Net pure Java Driver - A native-protocol fully Java technology-enabled driver converts JDBC technology calls into the network protocol used by DBMSs directly. This allows a direct call from the client machine to the DBMS server and is a practical solution for Intranet access. Since many of these protocols are proprietary the database vendors themselves will be the primary source for this style of driver. Several database vendors have these in progress.
복습용 저장

복습용 저장

이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.

내 학습 라이브러리 열기
도움이 되었나요?
Add Comment View Comments
Ques 16

What are the different JDB drivers available?

There are mainly four type of JDBC drivers available. They are:

Type 1 : JDBC-ODBC Bridge Driver - A JDBC-ODBC bridge provides JDBC API access via one or more ODBC drivers. Note that some ODBC native code and in many cases native database client code must be loaded on each client machine that uses this type of driver. Hence, this kind of driver is generally most appropriate when automatic installation and downloading of a Java technology application is not important. For information on the JDBC-ODBC bridge driver provided by Sun.

Type 2: Native API Partly Java Driver- A native-API partly Java technology-enabled driver converts JDBC calls into calls on the client API for Oracle, Sybase, Informix, DB2, or other DBMS. Note that, like the bridge driver, this style of driver requires that some binary code be loaded on each client machine.

Type 3: Network protocol Driver- A net-protocol fully Java technology-enabled driver translates JDBC API calls into a DBMS-independent net protocol which is then translated to a DBMS protocol by a server. This net server middleware is able to connect all of its Java technology-based clients to many different databases. The specific protocol used depends on the vendor. In general, this is the most flexible JDBC API alternative. It is likely that all vendors of this solution will provide products suitable for Intranet use. In order for these products to also support Internet access they must handle the additional requirements for security, access through firewalls, etc., that the Web imposes. Several vendors are adding JDBC technology-based drivers to their existing database middleware products.

Type 4: JDBC Net pure Java Driver - A native-protocol fully Java technology-enabled driver converts JDBC technology calls into the network protocol used by DBMSs directly. This allows a direct call from the client machine to the DBMS server and is a practical solution for Intranet access. Since many of these protocols are proprietary the database vendors themselves will be the primary source for this style of driver. Several database vendors have these in progress.
복습용 저장

복습용 저장

이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.

내 학습 라이브러리 열기
도움이 되었나요?
Add Comment View Comments
Ques 17

What is the fastest type of JDBC driver?

Type 4 (JDBC Net pure Java Driver) is the fastest JDBC driver. Type 1 and Type 3 drivers will be slower than Type 2 drivers (the database calls are make at least three translations versus two), and Type 4 drivers are the fastest (only one translation).
복습용 저장

복습용 저장

이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.

내 학습 라이브러리 열기
도움이 되었나요?
Add Comment View Comments
Ques 18

Is the JDBC-ODBC Bridge multi-threaded?

No. The JDBC-ODBC Bridge does not support multi threading. The JDBC-ODBC Bridge uses synchronized methods to serialize all of the calls that it makes to ODBC. Multi-threaded Java programs may use the Bridge, but they won't get the advantages of multi-threading.
복습용 저장

복습용 저장

이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.

내 학습 라이브러리 열기
도움이 되었나요?
Add Comment View Comments
Ques 19

How do you handle your own transaction?

Connection Object has a method called setAutocommit ( boolean flag) . For handling our own transaction we can set the parameter to false and begin your transaction . Finally commit the transaction by calling the commit method.
복습용 저장

복습용 저장

이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.

내 학습 라이브러리 열기
도움이 되었나요?
Add Comment View Comments

Most helpful rated by users:

Copyright © 2026, WithoutBook.