Programming in Java | Week 11

Session: JAN-APR 2024

Course name: Programming In Java

Course Link: Click Here

For answers or latest updates join our telegram channel: Click here to join

These are NPTEL Programming In Java Week 11 Assignment 11 Answers

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

Q2. How many types of JDBC drivers there? a. 3 b. 4 c. 8 d. 10

Q3. What is the correct sequence to create a database connection? i. Import JDBC packages. ii. Open a connection to the database. iii. Load and register the JDBC driver. iv. Execute the statement object and return a query resultset. v. Create a statement object to perform a query. vi. Close the resultset and statement objects. vii. Process the resultset. viii. Close the 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

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

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

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

Q7. Which of these obtains a Connection? a. Connection.getConnection(url) b. Driver.getConnection(url) c. DriverManager.getConnection(url) d. new Connection(url)

Q8. Which class provides methods to create a client-side socket in Java? a. ServerSocket b. NetSocket c. Socket d. ClientSocket

Q9. What does JDBC stand for? a. Java DataBase Connectivity b. Java DataBase Connection c. Java DataBase Control d. Java DataBase Connector

Q10. Which method can be used to query for a single object using JdbcTemplate? a. queryForObject() b. queryForList() c. query() d. singleQuery()

Programming Assignment

Question 1 The following code is missing some information needed to run the code. Add whatever is missing and make the code runnable.

Question 2 Write the JDBC codes needed to create a Connection interface using the DriverManager class and the variable DB_URL. Check whether the connection is successful using ‘isAlive(timeout)’ method to generate the output, which is either ‘true’ or ‘false’. Note the following points carefully: § Name the connection object as conn only. § Use timeout value as 1.

Question 3 Due to some mistakes in the below code, the code is not compiled/executable. Modify and debug the JDBC code to make it execute successfully.

Question 4 Complete the code segment to create a new table named ‘STUDENTS’ in SQL database using the following information.

Question 5 Complete the code segment to rename an already created table named ‘STUDENTS’ into ‘GRADUATES’.

More Weeks of Programming In Java: Click here

More Nptel Courses: https://progiez.com/nptel-assignment-answers

Session: JULY-DEC 2023

Course Name: Programming In Java

Question 1 Complete the code segment to insert the following data using prepared statement in the existing table ‘PLAYERS’.

Question 2 Write the required code in order to update the following data in the table ‘PLAYERS’.

Question 3 Write the appropriate code in order to delete the following data in the table ‘PLAYERS’.

Question 4 Complete the following program to calculate the average age of the players in the table ‘PLAYERS’. Structure of Table ‘PLAYERS’ is given below:

Question 5 Complete the code segment to drop the table named ‘PLAYERS’.

More Nptel Courses: Click here

Session: JAN-APR 2023

Course Name: Programming in Java

Q1. Which of the following interfaces is used to manage transactions in JDBC? a. Connection b. Statement c. Transaction d. ResultSet

Answer: a. Connection

Q2. Which of the following interfaces is used to execute parameterized SQL statements in JDBC? a. ResultSet b. PreparedStatement c. Statement d. Connection

Answer: b. PreparedStatement

Q3. Which of the following statements is true? a. The executeQuery( ) method of java.sql.Statement interface is used to execute a DELETE statement. b. The executeQuery( ) method of java.sql.Statement interface is used to execute a SELECT statement. c. The executeQuery( ) method of java.sql.Statement interface is used to execute a INSERT statement. d. The executeQuery( ) method of java.sql.Statement interface is used to execute a UPDATE statement.

Answer: b. The executeQuery( ) method of java.sql.Statement interface is used to execute a SELECT statement.

Q4. Which of the following statements is true? a. The executeUpdate( ) method of java.sql.Statement interface is used to execute a DELETE statement. b. The executeUpdate( ) method of java.sql. Statement interface is used to execute a SELECT statement. c. The executeUpdate( ) method of java.sql.Statement interface is used to execute a INSERT statement. d. The executeUpdate( ) method of java.sql.Statement interface is used to execute a UPDATE statement.

Answer: a, c, d

Q5. Which of the following statements is true about JDBC? a. JDBC is a programming language. b. JDBC is a type of database. c. JDBC is an API for accessing relational databases from Java programs. d. JDBC is used to create graphical user interfaces.

Answer: c. JDBC is an API for accessing relational databases from Java programs.

Q6. Which of the following statements is true about the PreparedStatement interface in JDBC? a. PreparedStatement objects are precompiled before they are executed. b. PreparedStatement objects can only be used for SELECT statements. c. PreparedStatement objects cannot accept parameters at runtime. d. PreparedStatement objects can be reused for multiple SQL statements.

Answer: a, d

Q7. Which of the following statements is true about batch updates in JDBC? a. Batch updates can only be used for INSERT statements. b. Batch updates allow multiple SQL statements to be executed in a single transaction. c. Batch updates are executed immediately as soon as they are added to the batch. d. Batch updates can be rolled back.

Answer: b, d

Q8. Consider the following code. What is the output of the above code? a. Compilation error b. Runtime error c. 1, “one” is replaced by 2.”two™ in the table. d. “one” and “two” both are inserted in different columns of same row.

Answer: d. “one” and “two” both are inserted in different columns of same row.

Q9. Which type of JDBC driver translates JDBC calls into native database API calls? a. Type 1 driver b. Type 2 driver c. Type 3 driver d. Type 4 driver

Answer: b. Type 2 driver

Q10. Which of the following method is static and synchronized in JDBC API? a. getConnection( ) b. prepareCall() c. executeUpdate( ) d. executeQuery()

Answer: a. getConnection( )

Programming Assignment of Programming in Java

Complete the code segment  to insert the following data using prepared statement in the existing table ‘ PLAYERS ’ .

Write the required code in order to update the following data in the table ‘ PLAYERS ’.

Write the appropriate code in order to delete the following data in the table ‘ PLAYERS ’.

Complete the following program to  calculate the average age of the players in the table ‘ PLAYERS ’ .

Complete the code segment to  drop the table named ‘ PLAYERS ’ .

More Weeks of Programming In Java: Click Here

More Nptel courses: https://progiez.com/nptel-assignment-answers/

These are NPTEL Programming In Java Week 11 Assignment 11 Answers