0% found this document useful (0 votes)
10 views

Unit 4

Uploaded by

manojschavan6
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Unit 4

Uploaded by

manojschavan6
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 52

unit 4

1. A Java program cannot directly communicate with an ODBC driver because:


- A) ODBC written in C language
- B) JDBC technology-based driver ("JDBC driver") makes it possible to do
- C) All mentioned above
- D) Abbreviate the term DSN
- Answer: A) ODBC written in C language

2. A JDBC technology-based driver ("JDBC driver") makes it possible to do:


- A) ODBC written in C language
- B) All mentioned above
- C) Data Source Name
- D) application program interface
- Answer: B) All mentioned above

3. Abbreviate the term DSN:


- A) Data Source Name
- B) All mentioned above
- C) Determines whether the ResultSet cursor points to the last row of the ResultSet
- D) Driver Manager
- Answer: A) Data Source Name

4. An API can be created for:


- A) ODBC written in C language
- B) JDBC technology-based driver ("JDBC driver") makes it possible to do
- C) All of these
- D) application program interface
- Answer: C) All of these

1|Page
unit 4

5. API stands for:


- A) ODBC written in C language
- B) JDBC technology-based driver ("JDBC driver") makes it possible to do
- C) Data Source Name
- D) application program interface
- Answer: D) application program interface
6. API which controls access to the row result of a given Statement and holds data retrieved
from a database after you execute an SQL query using Statement objects:
- A) java.sql.ResultSet
- B) sun.jdbc.odbc.JdbcOdbcDriver
- C) ClassNotFoundException
- D) DriverManager
- Answer: A) java.sql.ResultSet

7. Application Server used in ____________________:


- A) Three-Tier Mode
- B) Driver Manager
- C) GUI
- D) Data Source Name
- Answer: A) Three-Tier Mode
8. Backbone of JDBC Architecture is ________________:
- A) Stored Procedures
- B) Driver Manager
- C) executeUpdate()
- D) java.sql.ResultSet
- Answer: B) Driver Manager
9. boolean isLast() method defines _______:
- A) Determines whether the ResultSet cursor points to the last row of the ResultSet
- B) Calling procedure
- C) Stored Procedures
- D) executeUpdate()
- Answer: A) Determines whether the ResultSet cursor points to the last row of the ResultSet

2|Page
unit 4

10. Callable Statement used to ________:


- A) All of these
- B) calling procedure
- C) stored procedure
- D) executeUpdate()
- Answer: C) stored procedure

11. Callable statement object in JDBC is used to execute a call to:


- A) Stored Procedures
- B) calling procedure
- C) executeUpdate()
- D) Three-Tier Mode
- Answer: A) Stored Procedures

12. CallableStatement is used to execute_________________:


- A) Stored Procedures
- B) executeQuery()
- C) executeUpdate()
- D) DriverManager
- Answer: A) Stored Procedures

13. Choose the correct syntax for getConnection() method:


- A) public static Connection getConnection(String url, String name, String
password)SQLException
- B) sun.jdbc.odbc.JdbcOdbcDriver
- C) executeUpdate()
- D) DriverManager
- Answer: A) public static Connection getConnection(String url, String name, String
password)SQLException

3|Page
unit 4

14. Class.forName("_________________________"):
- A) sun.jdbc.odbc.JdbcOdbcDriver
- B) All of these
- C) Data Source Name
- D) application program interface
- Answer: A) sun.jdbc.odbc.JdbcOdbcDriver

15. class.forName() method throws:


- A) ClassNotFoundException
- B) application program interface
- C) DriverManager
- D) java.sql.ResultSet
- Answer: A) ClassNotFoundException

16. Connection object can be initialized using the _______ method of the DriverManager Class:
- A) executeUpdate()
- B) getConnection()
- C) PreparedStatement
- D) ResultSet
- Answer: B) getConnection()
17. createStatement() method without any parameter is used to create a statement with:
- A) a forward only and read only ResultSet
- B) DriverManager
- C) Data Source Name
- D) application program interface
- Answer: A) a forward only and read only ResultSet
18. Database meta data are retrieved through ________:
- A) a PreparedStatement object
- B) DriverManager
- C) executeUpdate()
- D) ResultSet
- Answer: D) ResultSet

4|Page
unit 4

19. DELETE statement of an SQL is executed by ______________:


- A) executeUpdate()
- B) executeQuery()
- C) ResultSet
- D) DriverManager
- Answer: A) executeUpdate()

20. DriverManager.getConnection(_______ , ______ , ______) What are the two parameters that
are included?
- A) URL or machine name where server runs, User ID, Password
- B) executeUpdate(), Data Source Name, application program interface
- C) PreparedStatement, DriverManager, ResultSet
- D) java.sql.ResultSet, executeQuery(), executeUpdate()
- Answer: A) URL or machine name where server runs, User ID, Password

21. DSN stands for:


- A) Data Source Name
- B) Stored Procedures
- C) executeUpdate()
- D) DriverManager
- Answer: A) Data Source Name
22. Every driver must provide a class that should implement the __________________:
- A) Stored Procedures
- B) DriverManager
- C) Driver interface
- D) executeUpdate()
- Answer: C) Driver interface
23. Execution of delete SQL query in JDBC, __________ method must be used:
- A) executeUpdate()
- B) executeQuery()
- C) ResultSet
- D) DriverManager
- Answer: A) executeUpdate()

5|Page
unit 4

24. Following is the return type of executeUpdate( ):


- A) int
- B) boolean
- C) String
- D) DriverManager
- Answer: A) int

25. For the execution of INSERT SQL query in JDBC, ___________ method must be used:
- A) executeUpdate()
- B) executeQuery()
- C) ResultSet
- D) DriverManager
- Answer: A) executeUpdate()

26. For the execution of SELECT SQL query in JDBC, _______________ method must be used:
- A) executeQuery()
- B) executeUpdate()
- C) PreparedStatement
- D) DriverManager
- Answer: A) executeQuery()

27. forName is a _______________ type method:


- A) static
- B) final
- C) public
- D) private
- Answer: A) static

6|Page
unit 4

28. getConnection() method of which class:


- A) DriverManager
- B) ResultSet
- C) Connection
- D) PreparedStatement
- Answer: A) DriverManager

29. getUserName() method is used to _______:


- A) retrieve name of user
- B) executeUpdate()
- C) ResultSet
- D) DriverManager
- Answer: A) retrieve name of user

30. How can you execute DML statements (i.e., insert, delete, update) in the database?
- A) By invoking the executeUpdate(...) method of a Statement object
- B) Using executeQuery() method of ResultSet
- C) DriverManager
- D) PreparedStatement
- Answer: A) By invoking the executeUpdate(...) method of a Statement object

Of course! Here are the remaining multiple-choice questions:

31. How can you retrieve information from a ResultSet?


- A) By invoking the special getter methods on the ResultSet: getString(...), getBoolegetInt(…)
- B) By using executeQuery() method
- C) DriverManager
- D) PreparedStatement
- Answer: A) By invoking the special getter methods on the ResultSet: getString(...),
getBoolegetInt(…)

7|Page
unit 4

32. How many JDBC driver types are available by Sun Microsystems?
- A) Four
- B) Five
- C) Two
- D) Three
- Answer: A) Four

33. How many steps are used to connect any Java application with the database using JDBC?
- A) Five
- B) Six
- C) Four
- D) Three
- Answer: A) Five

34. How many transaction isolation levels are defined in java.sql.Connection interface?
- A) Five
- B) Six
- C) Four
- D) Three
- Answer: A) Five

35. If a PreparedStatement is a SQL SELECT statement, you execute the statement using
__________.
- A) PreparedStatement.executeQuery();
- B) PreparedStatement.executeUpdate();
- C) PreparedStatement.execute();
- D) DriverManager
- Answer: A) PreparedStatement.executeQuery();

8|Page
unit 4

36. If you need to use a stored procedure with output parameters, which of the following
statement type should be used to call the procedure?
- A) CallableStatement
- B) PreparedStatement
- C) Statement
- D) DriverManager
- Answer: A) CallableStatement

37. In 2-tier architecture, the first tier is generally _________________________:


- A) GUI
- B) Database
- C) Application Server
- D) DriverManager
- Answer: A) GUI

38. In JDBC _________ imports all Java classes concerned with database connectivity.
- A) java.sql.
- B) DriverManager
- C) Connection
- D) PreparedStatement
- Answer: A) java.sql.

39. In the following JDBC drivers, which is known as partly java driver?
- A) Native-API driver
- B) Thin driver
- C) Network Protocol driver
- D) DriverManager
- Answer: A) Native-API driver

9|Page
unit 4

40. In the three-tier model, the middle tier of the services acts as a mediator between
______________________ and _____________________.
- A) Java application and databases
- B) GUI and Database
- C) Network and Server
- D) DriverManager and Connection
- Answer: A) Java application and databases

41. In which model does a Java application or applet support database access?
- A) Both a and b
- B) Only a
- C) Only b
- D) None of the above
- Answer: A) Both a and b

42. In which type of driver must ODBC drivers be loaded on the client machine?
- A) Type 1
- B) Type 2
- C) Type 3
- D) Type 4
- Answer: A) Type 1

43. Invoking Class.forName() method may throw ___________.


- A) ClassNotFoundException
- B) SQLException
- C) DriverException
- D) DriverManagerException
- Answer: A) ClassNotFoundException

10 | P a g e
unit 4

44. JDBC is a _______________ interface, which means that it is used to invoke SQL commands
directly.
- A) High-level
- B) Low-level
- C) Medium-level
- D) Advanced-level
- Answer: B) Low-level

45. JDBC stands for:


- A) Java Datbase Connectivity
- B) Java Database Connection
- C) Java Database Connectivity
- D) Java DBMS Connectivity
- Answer: C) Java Database Connectivity

46. JDBC stands for:


- A) Java Datbase Connectivity
- B) Java Database Connection
- C) Java Database Connectivity
- D) Java DBMS Connectivity
- Answer: C) Java Database Connectivity

47. JDBC-ODBC bridge product provides _________ access via ____________.


- A) JDBC driver, ODBC drivers
- B) ODBC driver, JDBC drivers
- C) JDBC protocol, ODBC drivers
- D) ODBC protocol, JDBC drivers
- Answer: A) JDBC driver, ODBC drivers

11 | P a g e
unit 4

48. Methods of ResultSet() throws ____________.


- A) SQLException
- B) ClassNotFoundException
- C) DriverException
- D) SQLSyntaxException
- Answer: A) SQLException

49. Microsoft Access stores data in a _______________ file format.


- A) .MDB
- B) .DB
- C) .ACCDB
- D) .SQL
- Answer: A) .MDB

50. Name the type number belongs to JDBC-ODBC Bridge driver?


- A) Type 1
- B) Type 2
- C) Type 3
- D) Type 4
- Answer: A) Type 1

51. Native API converts ___________________ into the ___________________ used by DBMS.
- A) JDBC API, Native API calls
- B) JDBC calls, network protocol
- C) ODBC calls, JDBC API
- D) Network protocol, JDBC calls
- Answer: A) JDBC API, Native API calls

12 | P a g e
unit 4

52. Native-protocol pure Java converts ____________ into the ____________ used by DBMSs
directly.
- A) ODBC calls, JDBC API
- B) JDBC calls, network protocol
- C) Network protocol, JDBC calls
- D) ODBC API, Native API calls
- Answer: B) JDBC calls, network protocol

53. ODBC Drivers are platform _______________.


- A) Independent
- B) Dependent
- C) Neutral
- D) Variable
- Answer: B) Dependent

54. ODBC is not appropriate for direct use from Java because it uses a _______________.
- A) Java interface
- B) JDBC interface
- C) C interface
- D) Python interface
- Answer: C) C interface

55. ODBC minimum SQL grammar contains:


- A) INSERT, UPDATE, DELETE ONLY
- B) SELECT, INSERT, DELETE, UPDATE
- C) SELECT, UPDATE, DELETE ONLY
- D) INSERT, UPDATE, DELETE, SELECT
- Answer: A) INSERT, UPDATE, DELETE ONLY

13 | P a g e
unit 4

56. ODBC requires configuring _______ which represents the target database.
- A) Data Source Name
- B) Database URL
- C) Database Name
- D) JDBC Connection
- Answer: A) Data Source Name

57. ODBC stands for:


- A) Open Database Connection
- B) Oracle Database Connectivity
- C) Object-Oriented Database Connectivity
- D) None of the above
- Answer: A) Open Database Connection

58. PreparedStatement object in JDBC is used to execute______________Queries.


- A) Stored Procedure
- B) Parameterized
- C) Dynamic
- D) Static
- Answer: B) Parameterized

59. PreparedStatements are used for calling_____________.


- A) Callable Statements
- B) Stored Procedures
- C) Dynamic Queries
- D) Static Queries
- Answer: B) Stored Procedures

60. prepareStatement method is from which class?


- A) Connection Class
- B) Statement Class

14 | P a g e
unit 4

- C) ResultSet Class
- D) PreparedStatement Class
- Answer: A) Connection Class

61. Return type of execute() method is:


A) int
B) String
C) void
D) boolean
Answer: D) boolean

62. SQL stands for ________.


A) Structured Question Language
B) Structured Query Logic
C) Structured Query Language
D) Systematic Query Language
Answer: C) Structured Query Language

63. Statement is__________.


A) a class
B) an abstract class
C) an interface
D) a method
Answer: C) an interface

64. The JDBC –ODBC Bridge is________


A) Single-threaded
B) Multithreaded

15 | P a g e
unit 4

C) Non-threaded
D) Asynchronous
Answer: B) Multithreaded

65. The -----------------method executes a simple query and returns a single Result Set object
A) executeUpdate()
B) executeQuery()
C) execute()
D) executeFetch()
Answer: B) executeQuery()

66. The .................. object provides you with methods to access data from the table.
A) Connection
B) PreparedStatement
C) ResultSet
D) Statement
Answer: C) ResultSet

67. The ...................... method sets the query parameters of the PreparedStatement Object.
A) setParameters()
B) setValues()
C) setQueryParams()
D) setString()
Answer: D) setString()

68. The ........................ object allows you to execute parameterized queries.


A) ResultSet
B) Statement
C) CallableStatement
D) PreparedStatement

16 | P a g e
unit 4

Answer: D) PreparedStatement

69. The ......................... method executes an SQL statement that may return multiple results.
A) executeQuery()
B) executeUpdate()
C) execute()
D) executeMultiple()
Answer: C) execute()

70. The ............................. package contains classes that help in connecting to a database,
sending SQL statements to the database, and processing the query results.
A) java.sql
B) java.connection
C) java.jdbc
D) java.db
Answer: A) java.sql
71. The command to remove all the rows from a table 'CUSTOMER' is:
A) DELETE FROM CUSTOMER
B) REMOVE FROM CUSTOMER
C) TRUNCATE CUSTOMER
D) DROP FROM CUSTOMER
Answer: A) DELETE FROM CUSTOMER

72. The correct string for loading Jdbc-Odbc bridge driver using Class.forName() method is:
A) sun.jdbc.odbc.JdbcOdbcDriver
B) java.jdbc.odbc.JdbcDriver
C) com.jdbc.odbc.JdbcOdbc

17 | P a g e
unit 4

D) oracle.jdbc.odbc.JdbcDriver
Answer: A) sun.jdbc.odbc.JdbcOdbcDriver

73. The First task in JDBC is _________________.


A) Initialize the database
B) Create a connection
C) Register a driver
D) Execute a query
Answer: C) Register a driver

74. The interface used to execute SQL stored procedures is:


A) PreparedStatement
B) CallableStatement
C) StatementExecutor
D) ProcedureStatement
Answer: B) CallableStatement

75. The JDBC API is an application interface of Java for connecting Java as ___________.
A) Backend
B) Middleware
C) Front End
D) Database
Answer: B) Middleware

76. The JDBC API is an application interface connecting Java as __________.


A) Middleware
B) Database
C) Backend

18 | P a g e
unit 4

D) Front End
Answer: D) Front End

77. The parameters of the PreparedStatement object are ______________ when the user clicks
on the Query button.
A) Opened
B) Closed
C) Initialized
D) Terminated
Answer: C) Initialized

78. The PreparedStatement ___________ symbol is a placeholder that is replaced by the input
parameter at runtime.
A) $
B) #
C) ?
D) @
Answer: C) ?

79. The ResultSet ______________ provides methods for retrieving and manipulating the results
of executed queries.
A) Executor
B) Interface
C) Processor
D) Iterator
Answer: B) Interface

80. The Type 3 architecture is _______________________.


A) JDBC-Net pure Java
B) JDBC-ODBC Bridge
C) Network Protocol driver

19 | P a g e
unit 4

D) Native API partly Java driver Answer: A) JDBC-Net pure Java

81. The valid constant to represent ResultSet type is ___________________.


A) FORWARD_ONLY
B) SCROLL_INSENSITIVE
C) SCROLL_SENSITIVE
D) All of the mentioned
Answer: D) All of the mentioned

82. The _____ object provides you with methods to access data from the table.
A) Connection
B) PreparedStatement
C) ResultSet
D) Statement
Answer: C) ResultSet

83. The _____ package contains classes that help in connecting to a database, sending SQL
statements to the database, and processing the query results.
A) java.sql.
B) java.connection
C) java.jdbc
D) java.db
Answer: A) java.sql.

84. The ___________ interface provides various methods for getting information about the
Database.
A) DatabaseInfo
B) DBInfo
C) DatabaseMetaData

20 | P a g e
unit 4

D) DBMetaData
Answer: C) DatabaseMetaData

85. The ______________driver resolves JDBC calls and makes equivalent ODBC calls.
A) JDBC-ODBC bridge
B) Type 1 driver
C) Type 3 driver
D) Type 4 driver
Answer: A) JDBC-ODBC bridge

86. The ___________________ is the language for interacting with the Database.
A) Java
B) C++
C) Python
D) Structured Query Language (SQL)
Answer: D) Structured Query Language (SQL)

87. To execute an SQL query, which method is used?


A) executeQuery()
B) executeUpdate()
C) execute()
D) All of these
Answer: D) All of these

88. To retrieve a Connection object, which method is used?


A) createConnection()
B) getConnection()
C) retrieveConnection()

21 | P a g e
unit 4

D) obtainConnection()
Answer: B) getConnection()

89. Type 1 driver is also known as:


A) Native Protocol partly Java driver
B) JDBC-ODBC Bridge Driver
C) Thin driver
D) Network Protocol driver
Answer: B) JDBC-ODBC Bridge Driver

90. Type 3 driver is also known as ___________________.


A) Network Protocol driver
B) Thin driver
C) JDBC-net Pure Java
D) Native API partly Java driver
Answer: C) JDBC-net Pure Java

91. Type II JDBC driver is also known as __________________.


A) Native API partly Java driver
B) Network Protocol driver
C) Thin driver
D) JDBC-ODBC Bridge Driver
Answer: A) Native API partly Java driver

92. Type IV JDBC driver is also known as __________________.


A) Native Protocol Pure-Java Driver
B) Thin driver
C) Network Protocol driver

22 | P a g e
unit 4

D) JDBC-ODBC Bridge Driver


Answer: A) Native Protocol Pure-Java Driver

93. Type 4 driver is also known as:


A) JDBC-ODBC Bridge Driver
B) Native Protocol Pure-Java Driver
C) Thin driver
D) Network Protocol driver
Answer: B) Native Protocol Pure-Java Driver

94. What is JDBC?


A) Java Database Connection
B) Java Database Connectivity
C) Java Database Control
D) Java Database Console
Answer: B) Java Database Connectivity

95. What maintains a cursor pointing to a particular row of data initially? Cursor points to
before the first row.
A) ResultSet interface
B) Statement interface
C) DatabaseMetaData interface
D) Connection interface
Answer: A) ResultSet interface

96. Where does the object of ResultSet maintain a cursor?


A) First Row
B) Last Row
C) Between Rows

23 | P a g e
unit 4

D) Before First Row


Answer: D) Before First Row

97. Which among the below is not an interface of java.sql Package?


A) ResultSetStatement
B) PreparedStatement
C) CallableStatement
D) Statement
Answer: A) ResultSetStatement

98. Which are the JDBC components?


A) Driver, Connection, Statement, ResultSet
B) DriverManager, Connection, PreparedStatement, ResultSet
C) All of the above
D) None of the above
Answer: C) All of the above

99. Which class is used to connect a Java application to a JDBC driver?


A) JdbcDriver
B) DriverManager
C) JdbcConnector
D) JdbcManager
Answer: B) DriverManager

100. Which class/interface is used for an SQL statement that is executed frequently?
A) PreparedStatement
B) CallableStatement
C) Statement

24 | P a g e
unit 4

D) ResultSet
Answer: A) PreparedStatement

101. Which driver provides JDBC API access via one or more ODBC drivers?
- a) JDBC-ODBC Bridge Driver
- b) Type-2 Driver
- c) Type-3 Driver
- d) Type-4 Driver
- Answer: a) JDBC-ODBC Bridge Driver

102. Which driver is called as a thin driver in JDBC?


- a) Type-1 Driver
- b) Type-2 Driver
- c) Type-3 Driver
- d) Type-4 Driver
- Answer: d) Type-4 Driver

103. Which driver is efficient and always preferable for using JDBC applications?
- a) Type-1
- b) Type-2
- c) Type-3
- d) Type-4
- Answer: d) Type-4

104. Which driver is needed to connect to the Microsoft database?


- a) Type-1 Driver
- b) Type-2 Driver
- c) Type-3 Driver

25 | P a g e
unit 4

- d) JDBC-ODBC Bridge Driver


- Answer: d) JDBC-ODBC Bridge Driver

105. Which driver type uses middleware server (Application Server)?


- a) Type 1
- b) Type 2
- c) Type 3
- d) Type 4
- Answer: c) Type 3

106. Which from the below use "middle-tier"?


- a) Type-1
- b) Type-2
- c) Type-3
- d) All of the above
- Answer: d) All of the above

107. Which interface is important from java.sql package in JDBC?


- a) Statement
- b) ResultSet
- c) Connection
- d) DatabaseMetaData
- Answer: c) Connection

108. Which Interface is used to execute dynamic SQL statements?


- a) Statement
- b) PreparedStatement
- c) CallableStatement

26 | P a g e
unit 4

- d) ResultSet
- Answer: b) PreparedStatement

109. Which interface provides methods to execute queries with the database?
- a) Statement interface
- b) ResultSet interface
- c) Connection interface
- d) PreparedStatement interface
- Answer: a) Statement interface

110. Which is the default ResultSet type?


- a) TYPE_FORWARD_ONLY
- b) TYPE_SCROLL_SENSITIVE
- c) TYPE_SCROLL_INSENSITIVE
- d) TYPE_DYNAMIC
- Answer: a) TYPE_FORWARD_ONLY

111. Which is not a type of JDBC driver?


- a) JDBC-Native pure Java
- b) Type-1 Driver
- c) Type-3 Driver
- d) Type-4 Driver
- Answer: a) JDBC-Native pure Java

112. Which is the correct syntax of the next() method of ResultSet?


- a) boolean next()
- b) void next()
- c) int next()

27 | P a g e
unit 4

- d) String next()
- Answer: a) boolean next()

113. Which JDBC driver Type(s) can be used in either applet or servlet code?
- a) Type 1
- b) Type 2
- c) Both Type 3 and Type 4
- d) Neither Type 3 nor Type 4
- Answer: c) Both Type 3 and Type 4

114. Which JDBC driver Type(s) can you use in a three-tier architecture if the Web server and
the DBMS are running on the same machine?
- a) Type 1
- b) Type 2
- c) Both Type 3 and Type 4
- d) Neither Type 3 nor Type 4
- Answer: c) Both Type 3 and Type 4

115. Which JDBC driver Types are used for over communications networks?
- a) Type 1
- b) Type 2
- c) Both Type 3 and Type 4
- d) Neither Type 3 nor Type 4
- Answer: c) Both Type 3 and Type 4

116. Which kind of driver converts JDBC calls into calls on the client API for Oracle, Sybase,
Informix, IBM DB2, or other DBMS?
- a) JDBC-ODBC Bridge Driver
- b) Native-API partly-Java driver
- c) Thin driver

28 | P a g e
unit 4

- d) Thick driver
- Answer: b) Native-API partly-Java driver

117. Which method is used to obtain the count of total rows of ResultSet?
- a) getRowCount()
- b) countRows()
- c) getRow()
- d) getRowCountInResultSet()
- Answer: c) getRow()

118. Which method is used to perform DML statements in JDBC?


- a) executeQuery()
- b) executeUpdate()
- c) execute()
- d) performDML()
- Answer: b) executeUpdate()

119. Which method is used to send CREATE TABLE queries to the database using JDBC?
- a) executeQuery()
- b) execute()
- c) executeUpdate()
- d) createTable()
- Answer: c) executeUpdate()

120. Which method must be used to execute INSERT, UPDATE, or DELETE statements?
- a) executeQuery()
- b) execute()
- c) executeUpdate()

29 | P a g e
unit 4

- d) executeStatement()
- Answer: c) executeUpdate()

121. Which method of class is used to register & dynamically load the driver class?
- a) registerDriver()
- b) loadDriver()
- c) forName()
- d) initDriver()
- Answer: c) forName()

122. ___________ type of driver is very flexible and needs no code installation on the client
machine.
- a) Type 1-JDBC-ODBC Bridge
- b) Type 2-JDBC-Native API
- c) Type 3-JDBC-Net Pure Java
- d) Type 4-JDBC-Thin
- Answer: c) Type 3-JDBC-Net Pure Java

123. ________ moves the cursor to the specified row.


- a) public void moveToRow(int row)
- b) public boolean goTo(int row)
- c) public boolean move(int row)
- d) public boolean absolute(int row)
- Answer: d) public boolean absolute(int row)

124. ________ is an open-source DBMS product that runs on UNIX, Linux, and Windows.
- a) Oracle
- b) MySQL
- c) SQL Server

30 | P a g e
unit 4

- d) PostgreSQL
- Answer: b) MySQL

125. ___________ is the key to _________ with respect to RDBMS?


- a) Encryption, Security
- b) Indexing, Optimization
- c) Serialization, Persistence
- d) Transactions, Integrity
- Answer: c) Serialization, Persistence

126. ___________ Calls get converted into native C or C++ API calls.
- a) JDBC API
- b) JDBC Driver
- c) JDBC Statement
- d) JDBC Connection
- Answer: a) JDBC API

127. _______________ interface allows storing results of the query?


- a) ResultSet
- b) Statement
- c) Connection
- d) ResultSetMetaData
- Answer: a) ResultSet

128. __________________ method of Connection interface is used to create the Statement


object.
- a) createStatement()
- b) prepareStatement()
- c) executeQuery()
- d) getConnection()
- Answer: a) createStatement()

31 | P a g e
unit 4

129. __________________ method of DriverManager is used to establish a connection with the


database.
- a) createConnection()
- b) connect()
- c) getConnection()
- d) establishConnection()
- Answer: c) getConnection()

130. _____________________ Returns the current row number, with the first row starting at 1.
- a) getRowIndex()
- b) rowNumber()
- c) getRowNumber()
- d) getRow()
- Answer: d) getRow()

131. ………………… can not directly communicate with the database to submit data & retrieve
the result.
- a) Java
- b) JDBC
- c) Python
- d) C++
- Answer: b) JDBC

132. Which of the following statements loads the JDBC-ODBC driver?


- a) `Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")`
- b) `Class.loadDriver("sun.jdbc.odbc.JdbcOdbcDriver")`
- c) `DriverManager.loadDriver("sun.jdbc.odbc.JdbcOdbcDriver")`
- d) `DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver())`
- Answer: a) `Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")`

32 | P a g e
unit 4

133:Consider the following code. What should be the correction done in the code to get the
correct output?

import java.sql.;

public class mytabledelete {


public static void main(String[] args) throws Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String s = "jdbc:odbc:mystudtable";
Connection con = DriverManager.getConnection(s);
System.out.println("Connection Established");
PreparedStatement studste = con.prepareStatement("delete from student where rno=3");
studste.executeUpdate();
Statement s1 = con.createStatement();
String studqry = "select from student";
ResultSet Rset = s1.executeQuery(studqry);
while (Rset.next()) {
int studid = Rset.getInt("rno");
String studname = Rset.getString("name");
System.out.println(studid + " " + studname);
}
}
}
```

Options:
1. `String s= ("jdbc:odbc:mystudtable");`
2. `Both option i and ii`
3. `studste.executeUpdate();`
4. `Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");`

Correct Answer: Option 1 - `String s= ("jdbc:odbc:mystudtable");`

33 | P a g e
unit 4

134:Consider the following code. What will be the student table data after executing this code as
the table was empty?
import java.sql.;

public class mytableins {


public static void main(String[] args) throws Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String s = ("jdbc:odbc:mystudtable");
Connection con = DriverManager.getConnection(s);
System.out.println("Connection Established");
PreparedStatement studste = con.prepareStatement("insert into student values(2,'Rani')");
studste.executeUpdate();
Statement s1 = con.createStatement();
ResultSet Rset = s1.executeQuery("select from student");
System.out.println("Roll No ....Name");
while (Rset.next()) {
int studid = Rset.getInt("rno");
String studname = Rset.getString("name");
System.out.println(studid + " " + studname);
}
}
}
```

Options:
1. `4 N A 2`
2. `only one record in table`
3. `Missing Statement`
4. `Use satement Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");`

Correct Answer: Option 2 - `only one record in table`

34 | P a g e
unit 4

135:Consider the following code. Which statement needs to update the student table data by this
code?

import java.sql.;

public class mytableupdate {


public static void main(String[] args) throws Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String s = ("jdbc:odbc:mystudtable");
Connection con = DriverManager.getConnection(s);
System.out.println("Connection Established");
PreparedStatement studste = con.prepareStatement("update student set name='john' where
rno=2");
Statement s1 = con.createStatement();
String studqry = "select from student";
ResultSet Rset = stmt.executeQuery(studqry);
while (Rset.next()) {
int studid = Rset.getInt("rno");
String studname = Rset.getString("name");
System.out.println(studid + " " + studname);
}
}
}
```

Options:
1. `studste.executeUpdate();`
2. `Connection con = DriverManager.getConnection(s);`
3. `Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");`
4. `ResultSet Rset = stmt.executeQuery(studqry);`

Correct Answer: Option 1 - `studste.executeUpdate();`

35 | P a g e
unit 4

136:Consider the following database:

| ID | name | Salary |
|----|--------|--------|
| 1 | ramesh | 1200 |
| 2 | ganesh | 1111 |
| 6 | sanjay | 9500 |

What will be the correct output for the following code?

```java
import java.sql.;

class SelectDemo {
public static void main(String a[]) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded");
String url="jdbc:odbc:mydsn";
Connection con=DriverManager.getConnection(url);
System.out.println(" Connection to DataBase created");
Statement stmt=con.createStatement();
String query="select from emp";
ResultSet rs=stmt.executeQuery(query);
while(rs.next()) {
System.out.println(" ID : "+ rs.getInt(1));
System.out.println(" name : "+ rs.getString(2));
System.out.println(" Salary : "+ rs.getInt(3));
System.out.println();
}
} catch(ClassNotFoundException e) {

36 | P a g e
unit 4

e.printStackTrace();
} catch(SQLException e) {
e.printStackTrace();
}
}
}
```

Options:
1. Output showing records but with errors in formatting
2. `4 N A 2`
3. `Missing Statement`
4. `ResultSet rs=stmt.executeQuery(query);`

Correct Answer: Option 1 - Output showing records but with errors in formatting

137:Consider the following program. Select the statement that should be added to the program
to get the correct output.

```java
import java.sql.;

public class JdbcOdbc {


public static void main(String args[]) {
try {
Connection con;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:datastud");
try {
System.out.println("Getting All Rows from a table!");
Statement st = con.createStatement();
ResultSet res = ----------------------("SELECT FROM college");
System.out.println("student_code: " + "\t" + "student_name: ");

37 | P a g e
unit 4

while (res.next()) {
int i = res.getInt("stud_code");
String s = res.getString("stud_name");
System.out.println(i + "\t\t" + s);
}
con.close();
} catch (SQLException s) {
System.out.println("SQL code does not execute.");
}
} catch (Exception e) {
System.out.println("Error:connection not created");
}
}
}
```

Options:
1. `st.executeQuery()`
2. `res.executeQuery()`
3. `st.executeUpdate()`
4. `con.executeQuery()`

Correct Answer: Option 1 - `st.executeQuery()`

138:Consider the following program. Select the statement that should be added to the program
to get the correct output.

```java
import java.sql.;

public class db15 {


public static void main(String args[]) throws Exception {
Connection c = DriverManager.getConnection("jdbc:odbc:MyDSN","","");

38 | P a g e
unit 4

PreparedStatement s = c.prepareStatement("update db3 set Name=? where Roll_no=?");


Statement s = c.createStatement();
s.setString(1, args[0]);
s.setString(2, args[1]);
s.setString(3, args[2]);
s.executeUpdate();
ResultSet rs = s.executeQuery("select from db3");
System.out.println("Name" + "\t" + "Roll no" + "\t" + "Avg");
while(rs.next()) {
System.out.println(rs.getString(1) + "\t" + rs.getInt(2) + "\t" + rs.getDouble(3));
}
s.close();
c.close();
}
}
```

Options:
1. Use `satement Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");`
2. Missing Statement
3. `PreparedStatement s = c.prepareStatement("update db3 set Name=? where Roll_no=?");`
4. `Statement s = c.createStatement();`

Correct Answer: Option 2 - Missing Statement

139:Consider the following program. Select the statement that should be added to the program
to get the correct output.

```java
import java.sql.;

class create {
public static void main(String args[]) {

39 | P a g e
unit 4

try {
Class.forName("sun.jdbc.odbc.jdbcOdbcDriver");
System.out.printf("Driver Loaded");
String url = " jdbc.odbc.:dsn1";
Connection con = DriverManager.getConnection(url);
System.out.println("Connection established ");
String sql = "create table employee1(emp_id int,emp_name char";
PreparedStatement ps1 = con.prepareStatement(sql);
System.out.println("table created");
ps1.close();
con.close();
} catch(Exception e) {
}
}
}
```

Options:
1. `ps1.executeUpdate();`
2. Missing Statement
3. `PreparedStatement ps1 = con.prepareStatement(sql);`
4. `String url = " jdbc.odbc.:dsn1";`

Correct Answer: Option 2 - Missing Statement

140:Consider the following program. Select the statement that should be added to the program
to get the correct output.

```java
import java.sql.;
import java.io.;

40 | P a g e
unit 4

public class DeleteRecord4 {


public static void main (String args[]) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:mcm");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter rollno to delete:");
int rno = Integer.parseInt(br.readLine());
stmt.setInt(1, rno);
stmt.executeUpdate();
System.out.println("Record Deleted");
stmt.close();
conn.close();
br.close();
} catch(ClassNotFoundException ce) {
} catch(SQLException se) {
} catch(IOException ie) {
}
}
}
```

Options:
1. `PreparedStatement stmt=conn.prepareStatement("Delete from Stud wher");`
2. Missing Statement
3. `stmt.setInt(1, rno);`
4. `stmt.executeUpdate();`

Correct Answer: Option 2 - Missing Statement

141:Consider the following program. What correction should be done in the program to get the
correct output?

41 | P a g e
unit 4

```java
import java.sql.;
import java.io.;

class Create {
public static void main(String[] args) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:oraodbc", "scott", "tiger");
Statement stmt = con.createStatement();
stmt.executeUpdate("create table customers(CUST_NUM int, COMPANY char(20),
CUST_REP int, CREDIT_LIMIT number(7,2))");
stmt.close();
con.close();
System.out.println("Table Successfully created");
} catch(Exception e) {
e.printStackTrace();
}
}
}
```

Options:
1. Missing Statement
2. `Statement stmt = con.createStatement();`
3. `stmt.executeUpdate("create table customers(CUST_NUM int, COMPANY char(20), CUST_REP
int, CREDIT_LIMIT number(7,2))");`
4. `Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");`

Correct Answer: Option 1 - Missing Statement

142:Consider the following program. What will be displayed in the output?

42 | P a g e
unit 4

```java
import java.sql.;

class ConnectionTest {
public static void main(String srgs[]) {
try {
Class.forname("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver loaded");
String url="jdbc:odbc:xyz";
Connection con=DriverManager.getConnection(url);
System.out.println("connection to database created");
} catch(sQLException e) {
System.out.pritln("SQL error");
} catch(Exceptionn e) {
System.out.println("error");
}
}
}
```

Options:
1. Driver loaded Connection to database created
2. `4 N A 2`
3. Missing Statement
4. `Class.forname("sun.jdbc.odbc.JdbcOdbcDriver");`

Correct Answer: Option 4 - `Class.forname("sun.jdbc.odbc.JdbcOdbcDriver");`

Absolutely, here are the remaining multiple-choice questions:

143:Consider the following program. What will be the output of the following code?

43 | P a g e
unit 4

```java
import java.sql.;

public class db15 {


public static void main(String args[]) throws Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection("jdbc:odbc:DSN2", "", "");
Statement s = c.createStatement();
int n = s.executeUpdate("delete from db3");
ResultSet rs = s.executeQuery("select from db3");
System.out.println("Name" + "\t" + "Roll no" + "\t" + "Avg");
while(rs.next()) {
System.out.println(rs.getString(1) + "\t" + rs.getInt(2) + "\t" + rs.getDouble(3));
}
s.close();
c.close();
}
}
```

Options:
1. Empty Table
2. Missing Statement
3. `4 N A 2`
4. `SQLException`

Correct Answer: Option 1 - Empty Table

144:Consider the following program. Which package should be added to the program to get the
correct code?

```java
public class db15 {

44 | P a g e
unit 4

public static void main(String args[]) throws Exception {


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection("jdbc:odbc:Mybm", "", "");
PreparedStatement s = c.prepareStatement("update db3 set Name=? where Roll_no=?");
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select from db3");
System.out.println("Name" + "\t" + "Roll no" + "\t" + "Avg");
while(rs.next()) {
System.out.println(rs.getString(1) + "\t" + rs.getInt(2) + "\t" + rs.getDouble(3));
}
s.close();
c.close();
}
}
```

Options:
1. `java.sql.`
2. Missing Statement
3. `java.io.`
4. `java.util.`

Correct Answer: Option 1 - `java.sql.`

145:Consider the following program, what should be the correction done in the program to get
the correct output?

```java
import java.sql.;

public class displayemployee {


public static void main(String[] args) {
Connection con;

45 | P a g e
unit 4

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Connection established");
} catch(Exception e) {
System.out.println("Connection error");
}
try {
String str = "jdbc.odbc:dsn1";
con = DriverManager.getConnection(str, "", "");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("Selectfrom employee");
int n = rs.getMetaData().getColumnCount();
for(int i = 1; i <= n; i++) {
System.out.print(rs.getMetaData().getColumnLabel(i) + '\t');
System.out.println("");
while(rs.next()) {
for(int i = 1; i <= n; i++) {
System.out.print(rs.getString(i) + '\t');
}
System.out.println("");
}
rs.close();
con.close();
}
} catch(SQLException e) {
System.out.print("SQL error");
}
}
}
```

Options:

46 | P a g e
unit 4

1. Missing Statement
2. `for(int i = 1; i <= n; i++)`
3. `System.out.print(rs.getMetaData().getColumnLabel(i) + '\t');`
4. `System.out.print(rs.getString(i) + '\t');`

Correct Answer: Option 1 - Missing Statement

146:Consider the following program. Select the statement that should be added to the program
to get the correct output.

```java
import java.sql.;
class PreparedInsert {
public static void main(String a[]) {
Try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:javadb");
System.out.println(" Connection to DataBase created");
String a1 = "Insert into employee(id,name,salary) values(?,?,?)";
PreparedStatement ps = con.prepareStatement(a1);
ps.execute(a1);
System.out.println("Record Inserted");
String querySel = "Select from employee";
ResultSet rs = ps.executeQuery(querySel);

47 | P a g e
unit 4

System.out.println("After Insertion");
while(rs.next()) {
System.out.println(" ID : "+ rs.getInt(1));
System.out.println(" Name : "+ rs.getString(2));
System.out.println(" Salary : "+ rs.getInt(3));
System.out.println();
}
con.close();
} catch(SQLException e) {
System.out.println("SQL Error");
} catch(Exception e) {
System.out.println("Error");
}
}
}
`
Options:
1. All the above
2. `ps.execute(a1);`
3. `ResultSet rs = ps.executeQuery(querySel);`
4. `System.out.println("After Insertion");`

Correct Answer: Option 2 - `ps.execute(a1);`

147:Consider the following program and identify the missing statement.

```java
import java.sql.;
class Type4_simple {
public static void main(String[] args) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");

48 | P a g e
unit 4

String url = "jdbc:oracle:thin:@pearl:1521:oracle10g";


Connection conn = DriverManager.getConnection(url, "java", "java");
System.out.println("successfully connected");
} catch(Exception e) {
e.printStackTrace();
}
}
}
```
Options:
1. Missing semicolon & Package Statement
2. `ClassNotFoundException`
3. Missing Statement
4. `DriverManager.getConnection(url, "java", "java");`

Correct Answer: Option 1 - Missing semicolon & Package Statement

148:Consider the following program and identify the missing statement.

```java
public class SimpleDemo {
public static void main(String[] args) {
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
try {
String jdbcurl="jdbc:mysql://localhost:3306/test";
con=DriverManager.getConnection(jdbcurl, "root", "root");
System.out.println("Connection established");
stmt=con.createStatement();
rs=stmt.executeQuery("select from emp");
System.out.println("Empid \t Emap name \t City \t Salary");

49 | P a g e
unit 4

while(rs.next()) {
System.out.print(rs.getInt(1)+"\t");
System.out.print(rs.getString(2)+"\t");
System.out.print(rs.getString(3)+"\t");
System.out.print(rs.getFloat(4));
System.out.println();
}
} catch(ClassNotFoundException e) {
e.printStackTrace();
} catch(SQLException e) {
e.printStackTrace();
} finally {
try {
rs.close();
stmt.close();
con.close();
} catch(Exception e) {
}
}
}
}
```

Options:
1. All of the above
2. `catch(SQLException e) {e.printStackTrace()}`
3. `con=DriverManager.getConnection(jdbcurl, "root", "root");`
4. `rs=stmt.executeQuery("select from emp");`

Correct Answer: Option 1 - All of the above

149:Consider the following program. What should be the correction done in the program to get
the correct output?

50 | P a g e
unit 4

import java.sql.;
class ExecuteQueryTest {
public static void main(String args[]) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver loaded");
String url="jdbc:odbc:xyz";
Connection con = DriverManager.getConnection(url);
Statement state =con.createStatement();
System.out.println("Statement object created");
String sql= "select Name,Age from student";
ResultSet rs =state.executeQuery(sql);
String text = " ";
while (rs.next()) {
text+= rs.getString(1) + " " + rs .getInt (2) + '\n' ;
}
System.out.println(text);
} catch(Exception e) {
System.out.println(“error”);
}
}
}
```

Options:
1. `String sql= "select Name,Age from student";`
2. Missing Statement
3. `state.executeQuery(sql);`
4. `Connection con = DriverManager.getConnection(url);`

Correct Answer: Option 2 - Missing Statement

51 | P a g e
unit 4

52 | P a g e

You might also like