JDBC interview question set 1/JDBC Interview Questions and Answers for Freshers & Experienced

How Do I Start Debugging Problems Related To The Jdbc Api?

A good way to find out what JDBC calls are doing is to enable JDBC tracing. The JDBC trace contains a detailed listing of the activity occurring in the system that is related to JDBC operations.

If you use the DriverManager facility to establish your database connection, you use the DriverManager. setLogWriter method to enable tracing of JDBC operations. If you use a DataSource object to get a connection, you use the DataSource.setLogWriter method to enable tracing. (For pooled connections, you use the ConnectionPoolDataSource.setLogWriter method, and for connections that can participate in distributed transactions, you use the XADataSource.setLogWriter method.)

Posted Date:- 2021-09-04 05:19:48

What are the parameter types in Stored Procedures?

There are three types of parameters available in Stored Procedures. They are:

1. IN: Used to pass the input values to the procedure.
2. OUT: Used to get the value from the procedure.
3. IN/OUT: Used to pass the input values and get the value to/from the procedure.

Posted Date:- 2021-09-04 05:18:28

What's The Jdbc 3.0 Api?


The JDBC 3.0 API is the latest update of the JDBC API. It contains many features, including scrollable result sets and the SQL:1999 data types.

JDBC (Java Database Connectivity) is the standard for communication between a Java application and a relational database. The JDBC API is released in two versions; JDBC version 1.22 (released with JDK 1.1.X in package java.sql) and version 2.0 (released with Java platform 2 in packages java.sql and javax.sql). It is a simple and powerful largely database-independent way of extracting and inserting data to or from any database.

Posted Date:- 2021-09-04 05:17:10

What is the use of getGeneratedKeys() method in Statement?

Sometimes a table can have auto generated keys used to insert the unique column value for primary key. We can use Statement getGeneratedKeys() method to get the value of this auto generated key.

Posted Date:- 2021-09-04 05:16:18

How to set NULL values in JDBC PreparedStatement?

We can use PreparedStatement setNull() method to bind the null variable to a parameter. The setNull method takes index and SQL Types as argument, for example
ps.setNull(10, java.sql.Types.INTEGER);.

Posted Date:- 2021-09-04 05:15:34

List some exceptions that come under SQLException?

1. SQLNonTransientException
2. SQLTransientException
3. SQLRecoverableException

Posted Date:- 2021-09-04 05:14:38

What is savepoint and what are the methods we have in JDBC for savepoint?

Savepoint is used to create checkpoints in a transaction, and it allows us to perform a rollback to the specific savepoint. Once the transaction is committed or rolled backed, the savepoint that has been created for a transaction will be automatically destroyed and becomes invalid.

Posted Date:- 2021-09-04 05:12:23

How to change the auto-commit mode value?

By default, the value of AutoCommit is TRUE. After the execution of the SQL statement, it will be committed automatically. Using the setAutoCommit() method, we can change the value to AutoCommit.

Posted Date:- 2021-09-04 05:10:50

How many packages are available in JDBC API?

Two types of packages are available in JDBC API

1. java.sql
2. javax.sql

Posted Date:- 2021-09-04 05:10:08

What is the function of DriverManager class?

It is an interface between user and drivers. DriverManager tracks all the activity between a database and the appropriate driver.

Posted Date:- 2021-09-04 05:09:08

What is the difference between executing, executeQuery, executeUpdate in JDBC?

execute(): it can be used for any kind of SQL Query.

executeQuery() : it can be used for select query.

executeUpdate(): it can be used to change/update table.

Posted Date:- 2021-09-04 05:07:28

What do you mean by Metadata and why we are using it?

Metadata means data or information about other data. We use metadata to get database product version, driver name, the total number of tables and views.

Posted Date:- 2021-09-04 05:06:47

Can I get a null ResultSet?

No, we cannot get null Resultset. ResultSet.next() can return null if the next record does not contain a row.

Posted Date:- 2021-09-04 05:06:13

What are database warnings in JDBC and how can we handle database warnings in JDBC?

SQL warning or Database warning is the subclass of SQLException class. We can handle it by using getWarnings() method on Connection, Statement, and ResultSet.

Posted Date:- 2021-09-04 05:05:33

Why would you use setAutoCommit(false) in JDBC?

If you want to turn Off the Auto Commit then set connection.setAutoCommit(false)

Posted Date:- 2021-09-04 05:04:57

What is the use of JDBC DriverManager class?

JDBC DriverManager is the factory class through which we get the Database Connection object. When we load the JDBC Driver class, it registers itself to the DriverManager, you can look up the JDBC Driver classes source code to check this.

Then when we call DriverManager.getConnection() method by passing the database configuration details, DriverManager uses the registered drivers to get the Connection and return it to the caller program.

Posted Date:- 2021-09-04 05:03:42

What Is The Need Of Batchupdates?

The BatchUpdates feature allows us to group SQL statements together and send to database server in one single trip.

Posted Date:- 2021-09-04 05:03:09

Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection?

No, we can open only one Statement object when using the JDBC-ODBC Bridge.

Posted Date:- 2021-09-04 05:02:30

What do you mean by cold backup, hot backup?

This question is not directly related to JDBC but some time asked during JDBC interviews. The cold back is the backup technique in which backup of files are taken before the database is restarted. In hot backup of files and table is taken at the same time when the database is running. A warm is a recovery technique where all the tables are locked and users cannot access at the time of backing up data.

Posted Date:- 2021-09-04 05:01:44

What is connection pooling?

This is also one of the most popular question asked during JDBC Interviews. Connection pooling is the mechanism by which we reuse the recourse like connection objects which are needed to make connection with database .In this mechanism client are not required every time make new connection and then interact with database instead of that connection objects are stored in connection pool and client will get it from there. so it’s a best way to share a server resources among the client and enhance the application performance.

Posted Date:- 2021-09-04 05:01:15

How cursor works in the scrollable result set?

Another tough JDBC Interview question, not many Java programmer knows about using Cursor in Java. in JDBC 2.0 API new feature is added to move cursor in resultset backward forward and also in a particular row .
There are three constant define in result set by which we can move cursor.

· TYPE_FORWARD_ONLY: creates a non-scrollable result set, that is, one in which the cursor moves only forward
· TYPE_SCROLL_INSENSITIVE : a scrollable result set does not reflects changes that are made to it while it is open
· TYPE_SCROLL_SENSITIVE: a scrollable result set reflects changes that are made to it while it is open

Posted Date:- 2021-09-04 04:51:45

What is the 2 phase commit?

This is one of the most popular JDBC Interview questions and asked at an advanced level, mostly to senior Java developers on J2EE interviews. Two-phase commit is used in a distributed environment where multiple processes take part in the distributed transaction process. In simple word we can understand like if any transaction is executing and it will affect multiple databases then a two-phase commit will be used to make all database synchronized with each other.

In two-phase commit, commit or rollback is done by two phases:
1. Commit request phase: in this phase main process or coordinator process take vote of all other process that they are complete their process successfully and ready to commit if all the votes are “yes” then they go ahead for next phase. And if “No “then rollback is performed.
2. Commit phase: according to vote if all the votes are yes then commit is done.

Similarly when any transaction changes multiple database after execution of transaction it will issue pre commit command on each database and all database send acknowledgement and according to acknowledgement if all are positive transaction will issue the commit command otherwise rollback is done .

Posted Date:- 2021-09-04 04:50:51

What is the mean of “dirty read“ in database?

This kind of JDBC interview question is asked on 2 to 4 years experience Java programmer, they are expected to familiar with database transaction and isolation level etc. As the name it self convey the meaning of dirty read “read the value which may or may not be correct”. in database when one transaction is executing and changing some field value same time some another transaction comes and read the change field value before first transaction commit or rollback the value ,which cause invalid value for that field, this scenario is known as dirty read.

Posted Date:- 2021-09-04 04:50:14

How does JDBC API helps us in achieving loose coupling between Java Program and JDBC Drivers API?

JDBC API uses Java Reflection API to achieve loose coupling between java programs and JDBC Drivers. If you look at a simple JDBC example, you will notice that all the programming is done in terms of JDBC API and Driver comes in picture only when it’s loaded through reflection using Class.forName() method.

Posted Date:- 2021-09-04 04:49:36

What is JDBC API and when do we use it?

Java DataBase Connectivity API allows us to work with relational databases. JDBC API interfaces and classes are part of java.sql and javax.sql package. We can use JDBC API to get the database connection, run SQL queries and stored procedures in the database server and process the results.

JDBC API is written in a way to allow loose coupling between our Java program and actual JDBC drivers that make our life easier in switching from one database to another database servers easily.

Posted Date:- 2021-09-04 04:48:40

Explain the difference between RowSet vs. ResultSet in JDBC?

In a ResultSet handle connection to a DB, we cannot make Result as a serialized object.

Because of above issue, we cannot pass Resultset across the network.

RowSet extends the ResultSet interface, so it holds all methods from ResultSet. RowSet is serialized.

So, we can pass Rowset from one class to another class because it has no connection with the database.

Posted Date:- 2021-09-04 04:47:30

What Are The Different Types Of Rowset ?


There are two types of RowSet are there. They are:

1. Connected - A connected RowSet object connects to the database once and remains connected until the application terminates.

2. Disconnected - A disconnected RowSet object connects to the database, executes a query to retrieve the data from the database and then closes the connection. A program may change the data in a disconnected RowSet while it is disconnected. Modified data can be updated in the database after a disconnected RowSet reestablishes the connection with the database.

Posted Date:- 2021-09-04 04:45:09

What Is Rowset?

A RowSet is an object that encapsulates a set of rows from either Java Database Connectivity (JDBC) result sets or tabular data sources like a file or spreadsheet. RowSets support component-based development models like JavaBeans, with a standard set of properties and an event notification .

Posted Date:- 2021-09-04 04:44:17

Does The Jdbc-odbc Bridge Support Multiple Concurrent Open Statements Per Connection?

No. You can open only one Statement object per connection when you are using the JDBC-ODBC Bridge.

Posted Date:- 2021-09-04 04:43:50

Which Type Of Jdbc Driver Is The Fastest One?


JDBC Net pure Java driver(Type IV) is the fastest driver because it converts the JDBC calls into vendor specific protocol calls and it directly interacts with the database.

Posted Date:- 2021-09-04 04:43:23

How To Call A Stored Procedure From Jdbc ?


PL/SQL stored procedures are called from within JDBC programs by means of the prepareCall() method of the Connection object created. A call to this method takes variable bind parameters as input parameters as well as output variables and creates an object instance of the CallableStatement class. The following line of code illustrates this:

CallableStatement stproc_stmt = conn.prepareCall("{call procname(?,?,?)}");

Posted Date:- 2021-09-04 04:42:41

What Are Callable Statements ?

Callable statements are used from JDBC application to invoke stored procedures and functions.

Posted Date:- 2021-09-04 04:42:06

What Is Preparedstatement?

A prepared statement is an SQL statement that is precompiled by the database. Through precompilation, prepared statements improve the performance of SQL commands that are executed multiple times (given that the database supports prepared statements). Once compiled, prepared statements can be customized prior to each execution by altering predefined SQL parameters.

Posted Date:- 2021-09-04 04:41:43

What is the main purpose of the ResultSetMetaData interface?

This interface gives more information about ResultSet. Each ResultSet object has been associated with one ResultSetMetaData object.

This object will have the details of the properties of the columns like datatype of the column, column name, the number of columns in that table, table name, schema name, etc., getMetaData() method of ResultSet object is used to create the ResultSetMetaData object.

Syntax:

PreparedStatement pstmntobj = conn.prepareStatement(insert_query);

ResultSet resultsetobj = pstmntobj.executeQuery(“Select * from EMPLOYEE”);

ResultSetMetaData rsmd obj= resultsetobj.getMetaData();

Posted Date:- 2021-09-04 04:39:09

What Is Statement ?


<> Statement acts like a vehicle through which SQL commands can be sent. Through the connection object we create statement kind of objects.
<> Through the connection object we create statement kind of objects.
<> Statement stmt = conn.createStatement();
<> This method returns object which implements statement interface.

Posted Date:- 2021-09-04 04:38:19

What Does The Connection Object Represents?

The connection object represents communication context, i.e., all communication with database is through connection object only.

Posted Date:- 2021-09-04 04:37:25

What are the JDBC API components?

There are four types of components

1. JDBC API
2. JDBC Driver Manager
3. JDBC Test Suite
4. JDBC-ODBC Bridge

Posted Date:- 2021-09-04 04:36:15

Can we get the data of the particular row from the resultset?

Yes, we can get the data of the particular row from the resultSet using the relative() method. It will move the cursor to the given row either in a forward or in a backward direction from the current row. If the positive value has been given, it will move in the forward direction. If the negative value has been given, it will move in the backward direction.

Posted Date:- 2021-09-04 04:35:08

What are the concurrency modes in ResultSet?

There are 2 different modes of Concurrency in ResultSet. They are:

1. ResultSet.CONCUR_READ_ONLY: It is the default concurrency mode. A read-only option is available. Updation is not possible.

2. ResultSet.CONCUR_UPDATABLE: Updation is possible.

Posted Date:- 2021-09-04 04:34:08

What is the ResultSet interface?

ResultSet interface is used to store the output data after the SQL query execution. The object of ResultSet maintains the cursor point at the result data. As a default, the cursor points before the first row of the result data. We can traverse the data in the resultset objects as well.

Syntax:

Statement Interface:

Statement stmnt1 = conn.createStatement();

ResultSet resultset = stmnt1.executeQuery(“Select * from EMPLOYEE”);
PreparedStatement Interface:

PreparedStatement pstmnt1 = conn.prepareStatement(insert_query);

ResultSet resultset = pstmnt1.executeQuery(“Select * from EMPLOYEE”);

Posted Date:- 2021-09-04 04:33:23

How to call Stored Procedures in JDBC?

We can execute the SQL Stored procedures through the CallableStatement interface. The CallableStatement object can be created using the prepareCall() method of the Connection interface.

Posted Date:- 2021-09-04 04:32:56

What is DriverManager in JDBC?

DriverManager is an in-built class that is present in the java.sql package. It will be used as a mediator between the Java Application and DB, which we are connecting/using in our code. As a first step, we need to register or load the driver with DriverManager. Then the driver will be available to use in the application.

The main function of DriverManager is to load the driver class of the Database and create a connection with DB.

There are 2 ways to register or load the driver:

<> Class.forName()
<> DriverManager.registerDriver()

Posted Date:- 2021-09-04 04:32:29

What are the steps to connect with JDBC?

There are 6 basic steps to connect with DB in Java. These are enlisted below:

>> Import package
>> Load driver
>> Establish connection
>> Creation and execution of the statement
>> Retrieve results
>> Close connection

Posted Date:- 2021-09-04 04:31:36

What do you mean by DatabaseMetaData and why we are using it?

>> DatabaseMetaData is an interface that provides methods to obtain information about the database.

>> We can use this for getting database-related informations, such as database name, database version, driver name, the total number of tables or views, etc.

Posted Date:- 2021-09-04 04:30:33

Which data types are used for storing the image and file in the database table?

<> BLOB data type is used to store the image in the database. We can also store videos and audio by using the BLOB data type. It stores the binary type of data.

<> CLOB data type is used to store the file in the database. It stores the character type of data.

Posted Date:- 2021-09-04 04:29:27

Which type of JDBC driver is used by most people?

Type IV Thin driver is used in most of the applications. It is developed by the database vendor itself so the developers can use it directly without depending on any other sources. It allows for simple and easy development. It gives higher performance than the other drivers.

Posted Date:- 2021-09-04 04:27:51

What are the different types of drivers in JDBC?

There are 4 different JDBC drivers out there in the market.

They are:

Type I: JDBC – ODBC Bridge
Type II: Native API – Half Java Driver
Type III: Network Protocol– Totally Java Driver
Type IV: Thin Driver- Totally Java Driver
Type I: JDBC-ODBC Bridge

JDBC-ODBC bridge is going to behave as an interface between the client and the DB server. The client should put the JDBC-ODBC driver in it. The database ought to support the ODBC driver. If we are not concerned about the driver installation within the client system, we will use this driver.

Type II: Native API: Half Java Driver

It is almost like a JDBC-ODBC driver. Rather than an ODBC driver, we are using native API here. Libraries of the client-side database are used.

Type III: Network Protocol

It works like a 3-tier approach to access the database. An intermediate server will be used to connect to DB. JDBC method calls send data to an intermediate server then the server will communicate with DB.

Type IV: Thin Driver

It is absolutely written in Java. It explicitly converts JDBC method calls into the vendor-specific database protocol. Nowadays, Database merchant itself is providing this type of driver for their customers. So programmers don’t rely on other sources. It gives higher performance than the other drivers.

Posted Date:- 2021-09-04 04:27:26

What is ResultSet?

>> The java.sql.ResultSet interface represents the database result set, which is obtained after the execution of SQL query using Statement objects.

>> Object of ResultSet maintains a cursor pointing to the current row of data in the result set. Initially, the cursor is located before the first row. Then the cursor is moved to the next row by using the next() method. The next() method can be used to iterate through the result set with the help of a while loop. If there are no further rows, the next() method will return false.

>> Example for the creation of ResultSet is given below:
ResultSet rs = con.executeQuery(sqlQuery);

Posted Date:- 2021-09-04 04:26:34

What is the use of the JDBC driver?

It is a software component and is used to make the Java application to interact with the Database.

Posted Date:- 2021-09-04 04:23:36

What is JDBC?

Java Database Connectivity is unofficially known as JDBC. It is used to perform DB operations in Database from Java application. It supports interaction with any kind of DB like Oracle, MySQL, MS Access, etc.

Posted Date:- 2021-09-04 04:23:04

Search
R4R Team
R4R provides JDBC Freshers questions and answers (JDBC Interview Questions and Answers) .The questions on R4R.in website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,JDBC interview question set 1,JDBC Freshers & Experienced Interview Questions and Answers,JDBC Objetive choice questions and answers,JDBC Multiple choice questions and answers,JDBC objective, JDBC questions , JDBC answers,JDBC MCQs questions and answers R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for JDBC fresher interview questions ,JDBC Experienced interview questions,JDBC fresher interview questions and answers ,JDBC Experienced interview questions and answers,tricky JDBC queries for interview pdf,complex JDBC for practice with answers,JDBC for practice with answers You can search job and get offer latters by studing r4r.in .learn in easy ways .