Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What is Rowset?

Answer»
  • A RowSet is an object that encapsulates a row SET from EITHER JDBC result sets or tabular DATA sources such as files or spreadsheets. It supports component-based development models LIKE JavaBeans, with the help of a standard set of properties and event notifications.
  • The advantages of using RowSet are:
    • It is easier and flexible to use.
    • It is Scrollable and Updatable by default.
2.

What are the differences between ODBC and JDBC?

Answer»
ODBC(Open Database Connectivity)JDBC(Java Database Connectivity)
ODBC can be used for languages like C, C++, Java, etc.JDBC is used only for the Java language
We can USE ODBC only for the Windows platform, thus it is platform-dependent.We can use JDBC on any platform, thus it is platform-independent
Most of the ODBC Drivers DEVELOPED in native languages like C, C++JDBC drivers are developed using the Java language
It is not recommended to use ODBC for Java applications, because of LOW performance due to INTERNAL conversion.It is highly recommended to use JDBC for Java applications because there are no performance issues.
ODBC is procedural.JDBC is Object Oriented.
3.

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

Answer»
  • 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.
4.

What is stored procedure? What are the parameter types in stored procedure?

Answer»
  • STORED procedure is a group of SQL queries that are executed as a single logical unit to perform a specific task. Name of the procedure should be unique since each procedure is represented by its name.
  • For example, operations on an employee database like obtaining information about an employee COULD be coded as stored procedures that will be executed by an application. Code for creating a stored procedure named GET_EMP_DETAILS is given below:
DELIMITER $$DROP PROCEDURE IF EXISTS `EMP`.`GET_EMP_DETAILS` $$CREATE PROCEDURE `EMP`.`GET_EMP_DETAILS` (IN EMP_ID INT, OUT EMP_DETAILS VARCHAR(255))BEGIN SELECT first INTO EMP_DETAILS FROM Employees WHERE ID = EMP_ID;END $$DELIMITER ;

Stored procedures are called using CALLABLESTATEMENT class AVAILABLE in JDBC API. Below given code demonstrates this:

CallableStatement cs = con.prepareCall("{call GET_EMP_DETAILS(?,?)}");ResultSet rs = cs.executeQuery();
  • Three types of parameters are provided in the stored procedures. They are:
    • IN: It is used for passing the INPUT values to the procedure. With the help of setXXX() methods, you can bind values to IN parameters.
    • OUT: It is used for getting the value from the procedure. With the help of getXXX() methods, you can obtain values from OUT parameters.
    • IN/OUT: It is used for passing the input values and obtaining the value to/from the procedure. You bind variable values with the setXXX() methods and obtain values with the getXXX() methods.
5.

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

Answer»
  • 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.
6.

Which JDBC driver is fastest and used more commonly?

Answer»

JDBC Net pure Java DRIVER(Type 4 driver) is the fastest driver for localhost and remote connections because it directly interacts with the DATABASE by converting the JDBC CALLS into vendor-specific protocol calls.

7.

What is DriverManager in JDBC?

Answer»
  • JDBC DriverManager is a static class in Java, through which we manage the set of JDBC DRIVERS that are available for an application to use.
  • Multiple JDBC drivers can be used concurrently by an application, if necessary. By using a Uniform Resource Locator(URL), each application specifies a JDBC DRIVER.
  • When we load the JDBC Driver class into an application, it registers itself to the DriverManager by using Class.forName() or DriverManager.registerDriver(). To check this, you can have a look into the source CODE of JDBC Driver classes. After this, when we call DriverManager.getConnection() method by passing the details regarding DATABASE configuration, DriverManager will make use of REGISTERED drivers to obtain the connection and return it to the caller program.
8.

What is JDBC driver?

Answer»

JDBC driver is a software component having various classes and interfaces, that enables the Java application to interact with a database.

To connect with INDIVIDUAL databases, JDBC requires PARTICULAR drivers for each specific database. These drivers are provided by the database vendor in addition to the database. For example:

  • MYSQL Connector/J is the official JDBC driver for MySQL and we can locate the mysql-connector-java-<version>-bin.jar file among the installed files. On windows, this file can be obtained at
C:\Program Files (x86)\MySQL\MySQL Connector J\mysql-connector-java-5.1.30-bin.jar.
  • JDBC driver of Oracle 10G is ojdbc14.jar and it can be obtained in the installation directory of an Oracle at …/Oracle/app/oracle/product/10.2.0/server/jdbc/lib .

JDBC driver provides the connection to the database. Also, it implements the PROTOCOL for sending the query and result between client and database.

9.

What is ResultSet?

Answer»
  • 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);
10.

What is JDBC in Java?

Answer»

JDBC(Java Database Connectivity) is a Java API, which is helpful in INTERACTION with the database to retrieve, manipulate and process the data using SQL. It will make use of JDBC drivers for connecting with the database. By using JDBC, we can access tabular data stored in VARIOUS types of RELATIONAL databases such as Oracle, MYSQL, MS Access, etc.