Home Interview Questions and Answers JDBC Interview Questions and Answers For Freshers Part-1

jdbc1.What is JDBC?
JDBC stands for Java Database Connectivity, which is a standard Java API for database-independent connectivity between the Java programming language and a wide range of databases.

2.Describe a general JDBC Architecture.
General JDBC Architecture consists of two layers JDBC API (This provides the application-to-JDBC Manager connection) and JDBC Driver API (This supports the JDBC Manager-to-Driver Connection).

3.What are the common JDBC API components?
JDBC API consists of following interfaces and classes DriverManager, Driver, Connection, Statement, ResultSet, SQLException.

4.What is a JDBC DriverManager?
JDBC DriverManager is a class that manages a list of database drivers. It matches connection requests from the java application with the proper database driver using communication subprotocol.

5.What is a JDBC Driver?
JDBC driver is an interface enabling a Java application to interact with a database. To connect with individual databases, JDBC requires drivers for each database. The JDBC driver gives out the connection to the database and implements the protocol for transferring the query and result between client and database.

6.What is a connection?
Connection interface consists of methods for contacting a database. The connection object represents communication context.

7.What is a statement?
Statement encapsulates an SQL statement which is passed to the database to be parsed, compiled, planned and executed.

8.What is a ResultSet?
These objects hold data retrieved from a database after you execute an SQL query using Statement objects. It acts as an iterator to allow you to move through its data. The java.sql.ResultSet interface represents the result set of a database query.

9.What are types of ResultSet?
There are three constants which when defined in result set can move cursor in resultset backward, forward and also in a particular row.

ResultSet.TYPE_FORWARD_ONLY − The cursor can only move forward in the result set.

ResultSet.TYPE_SCROLL_INSENSITIVE − The cursor can scroll forwards and backwards, and the result set is not sensitive to changes made by others to the database that occur after the result set was created.

ResultSet.TYPE_SCROLL_SENSITIVE − The cursor can scroll forwards and backwards, and the result set is sensitive to changes made by others to the database that occur after the result set was created.

10.What are the basic steps to create a JDBC application?
Following are the basic steps to create a JDBC application

Import packages containing the JDBC classes needed for database programming.

Register the JDBC driver, so that you can open a communications channel with the database.

Open a connection using the DriverManager.getConnection () method.

Execute a query using an object of type Statement.

Extract data from result set using the appropriate ResultSet.getXXX () method.

Clean up the environment by closing all database resources relying on the JVM’s garbage collection.

You may also like

Leave a Comment