JDBC Interview Questions and answers latest 2022

  1. what are the different frequent JDBC classes or interfaces used in java code? Connection,DriverManager,ResultSet,Statement,PreparedStatement,CallableStatement.

What are different driver types supported in JDBC?

Driver TypeDescription
JDBC-ODBC bridgeIt is a bridge between client code and database machine
Type2 driverClient-side installation required to connect to database
Type3It uses middleware network to convert JDBC calls to native calls
Pure JavaDriverThe driver code is written in java and converts java code into native database-specific operations

2. How do you load the JDBC driver class?

Here are steps to load driver class into memory

  • Class.forName("DriverClass") is used load the driver class.
  • whenever DriverClass is loaded with this, create a new instance of DriverClass and register the driver with DriverManager Class.
  • Once Driver is registered, it is ready to create physical connections to a database using the Connection object.

What are the different types of statements in JDBC

There are three types of JDBC Statements.

StatementStatement is a factory class used to create a statement to execute SQL queries at runtime
PreparedStatementThese statements are used to run SQL queries with multiple query parameters and improve performance by avoiding compiling every time
CallableStatementThese are used to create statements to run native database procedure, These can be run with or without parameters

What is connection pooling?

Creating a database connection is like opening a socket connection to the remote machine, so this call is expensive.

whenever we have to do CRUD operations(create, read, update and delete) on data to the database, the Connection object is used for this. creating a connection for each operation is expensive. To avoid this, at the Initial state(application startup), create a pool of connections that are created and connected to the database.

whenever a database operation is needed by the application, the connection from the pool of connections is reused, once the operation is over, the connection is returned instead of closing(in case of normal connection) connection so that Database calls are reduced and non-performance is increased.

How do you storage image and files types into the database?

There are two types of data ie. images and files(excel, word, etc.)

Images are stored using BLOB and files are stored using CLOB

CLOB type stores the character data types into the database BLOB store the data in the format of binary data. Like images and audio and video files are converted to binary and stores it

Please write down the steps required to connect to Database

Here are steps load the JDBC driver and make a connection to the database.

  • add the required JDBC driver via maven or ant.
  • Import java classes
  • Load Driver using class.forName() class
  • Create a connection object
  • with connection object, Create Statement object
  • Execute the statement object and returns the result
  • Process the result
  • Finally, close the database connection.

What are resultSet types in java JDBC?

ResultSet is a result of database queries operation. There are different types provided to navigate the resultset

Forward-onlyforward cursor only and no scrolling
Scroll-insensitiveCursor can be changed to any direction and changes made here not reflected in database
Scroll-sensitiveCursor moves in forward or back direction, So any changes made to result reflect in database

What are ResultSet Concurrency types?

ResultSet.CONCUR_READ_ONLYAllows read only operation, no update operation
ResultSet.CONCUR_UPDATABLERead and update operations are possible