JDBC INTERVIEW QUESTIONS

 

1.  What is DriverManager in JDBC?

  • 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.


2. What are the Componenets of  JDBC

Components of JDBC:

There are four major components of JDBC using which it can interact with a database. They are:

  1. JDBC API: It provides different methods and interfaces for easier communication with the database. By using this, applications are able to execute SQL statements, retrieve results and make updation to the database. It has two packages as follows which consist of Java SE and Java EE platforms to exhibit Write Once Run Everywhere(WORA) capabilities.
    1. java.sql.*;
    2. javax.sql.*;
      Also, it provides a standard for connecting a database to a client application.
  2. JDBC DriverManager: It is the class in JDBC API. It loads the JDBC driver in a Java application for establishing a connection with the database. It is useful in making a database-specific call for processing the user request.
  3. JDBC Test suite: It is used to test the operations like insertion, deletion, updation etc., being performed by JDBC Drivers.
  4. JDBC-ODBC bridge drivers: It will connect database drivers to the database. JDBC-ODBC bridge interprets JDBC method call to the ODBC function call. It will use sun.jdbc.odbc package, which consists of the native library to access characteristics of ODBC.

3. Explain the difference between execute(), executeQuery() and executeUpdate() methods in JDBC.

execute() executeQuery() executeUpdate()
It can be used for any SQL statements.It is used to execute SQL Select queries.It is used to execute the SQL statements such as Insert/Update/Delete which will update or modify the database data.
It returns the boolean value TRUE if the result is a ResultSet object and FALSE when there is no ResultSet object.It returns the ResultSet object which contains the data retrieved by the SELECT statement.It returns an integer value which represents the number of affected rows where 0 indicates that the query returns null.
Used for executing both SELECT and non-SELECT queries.Used for executing only the SELECT Query.Used for executing only a non-SELECT query
.  

4. 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);

No comments:

Post a Comment