Programming In Java Week 11 NPTEL Assignment Answers 2025

NPTEL Programming In Java Week 11 Assignment Answers 2024

1. What is the correct order to close database resources?

a. Connection then Statement then ResultSet
b. ResultSet then Statement then Connection
c. Statement then Connection then ResultSet
d. Statement then ResultSet then Connection

Answer :- b
Explanation: In JDBC, the correct order to close resources is from the most specific to the most general: ResultSet → Statement → Connection. This ensures that dependent resources are not closed prematurely.


2. How many types of JDBC drivers are there?

a. 3
b. 4
c. 8
d. 10

Answer :- b
Explanation: JDBC provides four types of drivers: Type-1 (JDBC-ODBC bridge), Type-2 (Native-API), Type-3 (Network Protocol), and Type-4 (Thin driver).


3. What is the correct sequence to create a database connection?

a. i, ii, iii, v, iv, vii, viii, vi
b. i, iii, ii, v, iv, vii, vi, viii
c. ii, i, iii, iv, viii, vii, v, vi
d. i, iii, ii, iv, v, vi, vii, viii

Answer :- b
Explanation: The typical order is:

  1. Import packages →
  2. Load and register driver →
  3. Open connection →
  4. Create statement →
  5. Execute query →
  6. Process result →
  7. Close resultset & statement →
  8. Close connection.

4. Which of the following is correct about connection pooling?

a. Application server like WebLogic, WebSphere, jBoss and Tomcat provides the facilities to configure connection pooling.
b. Components like Apache Commons DBCP Component can be used to configure connection pooling.
c. Both of the above.
d. None of the above.

Answer :- c
Explanation: Both application servers and external libraries like Apache Commons DBCP support connection pooling to enhance performance.


5. Which of the following is used to test the operation?

a. JDBC API
b. JDBC Driver manager
c. JDBC Test suite
d. JDBC-ODBC Bridge Drivers

Answer :- c
Explanation: The JDBC Test Suite is specifically designed to test the JDBC drivers for conformance with the JDBC specification.


6. The JDBC architecture consists of _________ to access a database.

a. three-tier processing models
b. two-tier processing models
c. two-tier and three-tier processing models
d. None of the above

Answer :- c
Explanation: JDBC supports both two-tier (client connects directly to the database) and three-tier (client connects via a middleware server) architectures.


7. Which of these obtains a Connection?

a. Connection.getConnection(url)
b. Driver.getConnection(url)
c. DriverManager.getConnection(url)
d. new Connection(url)

Answer :- c
Explanation: The DriverManager.getConnection() method is used to establish a connection to the database using the specified URL.


8. Which class provides methods to create a client-side socket in Java?

a. ServerSocket
b. NetSocket
c. Socket
d. ClientSocket

Answer :- c
Explanation: The Socket class is used on the client side to initiate a connection to a server via TCP/IP.


9. What does JDBC stand for?

a. Java DataBase Connectivity
b. Java DataBase Connection
c. Java DataBase Control
d. Java DataBase Connector

Answer :- a
Explanation: JDBC stands for Java DataBase Connectivity, which is a Java API that manages connecting and executing queries with databases.


10. Which method can be used to query for a single object using JdbcTemplate?

a. queryForObject()
b. queryForList()
c. query()
d. singleQuery()

Answer :- a
Explanation: queryForObject() is used when you expect a single row to be returned. It maps the result directly to a single Java object.