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

UNIT - IV Interacting With Database CO:-4 Develop A Program Using Database MCQ Question Bank

The document contains a multiple choice question bank about interacting with databases in Java using JDBC. It includes 21 questions about JDBC concepts like connections, prepared statements, transactions, and result sets. Each question identifies the correct answer and provides a short explanation of the concept.

Uploaded by

Roman Empire
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views

UNIT - IV Interacting With Database CO:-4 Develop A Program Using Database MCQ Question Bank

The document contains a multiple choice question bank about interacting with databases in Java using JDBC. It includes 21 questions about JDBC concepts like connections, prepared statements, transactions, and result sets. Each question identifies the correct answer and provides a short explanation of the concept.

Uploaded by

Roman Empire
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

UNIT -IV Interacting With Database

CO:-4 Develop a Program using Database

MCQ Question Bank

Sr. Questions Bloom Marks


No Level

1 Which of the following contains both date and time? R 1


a) java.io.date
b) java.sql.date
c) java.util.date
d) java.util.dateTime

Answer: d
Explanation: java.util.date contains both date and time. Whereas,
java.sql.date contains only date.

2 Which of the following is advantage of using JDBC connection pool? R 1


a) Slow performance
b) Using more memory
c) Using less memory
d) Better performance

Answer: d
Explanation: Since the JDBC connection takes time to establish. Creating
connection at the application start-up and reusing at the time of requirement,
helps performance of the application.

3 Which of the following is advantage of using PreparedStatement in Java? R 1


a) Slow performance
b) Encourages SQL injection
c) Prevents SQL injection
d) More memory usage
Answer: c
Explanation: PreparedStatement in Java improves performance and also
1prevents from SQL injection.

4 Which one of the following contains date information? U 1


a) java.sql.TimeStamp
b) java.sql.Time
c) java.io.Time
d) java.io.TimeStamp

Answer: a
Explanation: java.sql.Time contains only time. Whereas,
java.sql.TimeStamp contains both time and date.

5 What does setAutoCommit(false) do? R 1


a) commits transaction after each query
b) explicitly commits transaction
c) does not commit transaction automatically after each query
d) never commits transaction

Answer: c
Explanation: setAutoCommit(false) does not commit transaction
automatically after each query. That saves a lot of time of the execution and
hence improves performance.

6 Which of the following is used to call stored procedure? U 1


a) Statement
b) PreparedStatement
c) CallableStatment
d) CalledStatement

Answer: c
Explanation: CallableStatement is used in JDBC to call stored procedure
from Java program.

7 Which of the following is used to limit the number of rows returned? U 1


a) setMaxRows(int i)
b) setMinRows(int i)
c) getMaxrows(int i)
d) getMinRows(int i)

Answer: a
Explanation: setMaxRows(int i) method is used to limit the number of rows
that the database returns from the query.

8 Which of the following is method of JDBC batch process? U 1


a) setBatch()
b) deleteBatch()
c) removeBatch()
d) addBatch()
Answer: d
Explanation: addBatch() is a method of JDBC batch process. It is faster in
processing than executing one statement at a time.

9 Which of the following is used to rollback a JDBC transaction? U 1


a) rollback()
b) rollforward()
c) deleteTransaction()
d) RemoveTransaction()
Answer: a
Explanation: rollback() method is used to rollback the transaction. It will
rollback all the changes made by the transaction.

10 Which of the following is not a JDBC connection isolation levels? U 1


a) TRANSACTION_NONE
b) TRANSACTION_READ_COMMITTED
c) TRANSACTION_REPEATABLE_READ
d) TRANSACTION_NONREPEATABLE_READ
Answer: d
Explanation: TRANSACTION_NONREPEATABLE_READ is not a JDBC
connection isolation level.

11 What are the major components of the JDBC? R 1

a)DriverManager, Driver, Connection, Statement, and ResultSet

b)DriverManager, Driver, Connection, and Statement

C)DriverManager, Statement, and ResultSet

d)DriverManager, Connection, Statement, and ResultSet


Answer: a

Explanation:

DriverManager: Manages a list of database drivers.

Driver: The database communications link, handling all communication


with the database.

Connection: Interface with all methods for contacting a database.

Statement: Encapsulates an SQL statement which is passed to the database


to be parsed, compiled, planned, and executed.

ResultSet: The ResultSet represents a set of rows retrieved due to query


execution.

12 Select the packages in which JDBC classes are defined? R 1

A)jdbc and javax.jdbc

B)rdb and javax.rdb

C)jdbc and java.jdbc.sql

D)sql and javax.sql

Answer: D

Explanation: JDBC API is divided into two packages i.e. java.sql and
javax.sql. We have to import these packages to use classes and interfaces in
our application.

13 Thin driver is also known as? R 1

Type 3 Driver

Type-2 Driver

Type-4 Driver

Type-1 Driver

Answer: c

Explanation: The JDBC thin driver is a pure Java driver. It is also known as
Type-4 Driver. It is platform-independent so it does not require any
additional Oracle software on the client-side. It communicates with the
server using SQL *Net to access Oracle Database.

14 What is the correct sequence to create a database connection? R 1


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.

i, ii, iii, v, iv, vii, viii, vi

i, iii, ii, v, iv, vii, vi, viii

ii, i, iii, iv, viii, vii, v, vi

i, iii, ii, iv, v, vi, vii, viii

Answer: b

Explanation: To create a database connection in Java, we must follow the


sequence given below:

Import JDBC packages.

Load and register the JDBC driver.

Open a connection to the database.

Create a statement object to perform a query.

Execute the statement object and return a query resultset.

Process the resultset.

Close the resultset and statement objects.

Close the connection.

15 Which of the following method is used to perform DML statements in U 1


JDBC?

executeResult()

executeQuery()
executeUpdate()

execute()

Answer: c

Explanation: We use the executeUpdate() method for DML SQL queries


that change data in the database, such as INSERT, UPDATE, and DELETE
which do not return a resultset.

16 How many transaction isolation levels provide the JDBC through the A 1
Connection interface?

a)3

b)4

c)7

D)2

Answer: b

Explanation:

17 Which of the following method is static and synchronized in JDBC API? U 1

getConnection()

prepareCall()

executeUpdate()

executeQuery()

Answer: A

Explanation: A Java application using the JDBC API establishes a


connection to a database by obtaining a Connection object. The standard
way to obtain a Connection object is to call the method
DriverManager.getConnection() method that accepts a String contains the
database connection URL. It is a static and synchronized method.

18 Which methods are required to load a database driver in JDBC? U 1

getConnection()

registerDriver()

forName()
Both b and c

Answer: d

Explanation: There are two ways to load a database driver in JDBC:

By using the registerDriver() Method: To access the database through a Java


application, we must register the installed driver in our program. We can do
this with the registerDriver() method that belongs to the DriverManager
class. The registerDriver() method takes as input a driver class, that is, a
class that implements the java.sql.Driver interface, as is the case with
OracleDriver.

By using the Class.forName() Method: Alternatively, we can also use the


forName() method of the java.lang.Class to load the JDBC drivers directly.
However, this method is valid only for JDK-compliant Java virtual
machines. It is invalid for Microsoft JVMs.

19 Parameterized queries can be executed by? U 1

ParameterizedStatement

PreparedStatement

CallableStatement and Parameterized Statement

All kinds of Statements

Answer: b

Explanation: The PreparedStatement interface extends the Statement


interface. It represents a precompiled SQL statement that can be executed
multiple times. It accepts parameterized SQL quires. We can pass 0 or more
parameters to this query.

20 Which of the following is not a valid statement in JDBC? U 1

Statement

PreparedStatement

QueryStatement

CallableStatement

Answer: c

Explanation:Statement: Use this for general-purpose access to your


database. It is useful when we are using static SQL statements at runtime.
The Statement interface cannot accept parameters.
PreparedStatement: It represents the pre-compiled SQL statements that can
be executed multiple times.

CallableStatement: It is used to execute SQL stored procedures.

QueryStatement: It is not supported by JDBC.

21 Identify the isolation level that prevents the dirty in the JDBC Connection U 1
class?

TRANSACTION_READABLE_READ

TRANSACTION_READ_COMMITTED

TRANSACTION_READ_UNCOMMITTED

TRANSACTION_NONE

Answer: b

Explanation: The isolation level TRANSACTION_READ_COMMITTED


prevents the dirty read but non-repeatable reads and phantom reads can
occur.

22 What does setAutoCommit(false) do? R 1

It will not commit transactions automatically after each query.

It explicitly commits the transaction.

It never commits the transactions.

It does not commit transaction automatically after each query.

Answer: b

Explanation: The way to allow two or more statements to be grouped into a


transaction is to disable the auto-commit mode. After the auto-commit mode
is disabled, no SQL statements are committed until we call the commit()
method explicitly.

23 What should be the correct order to close the database resource?What R 1


should be the correct order to close the database resource?

Connection, Statements, and then ResultSet

ResultSet, Connection, and then Statements

Statements, ResultSet, and then Connection

ResultSet, Statements, and then Connection


Answer: d

Explanation: The golden rule to JDBC connections and statements is to


close in the reverse order of initiation or opening. In addition, the ResultSet
is dependant on the execution of the Statement and the Statement is
dependant on the Connection instance. Hence, the closing should occur in
that order (ResultSet, Statement, and then Connection).

24 What should be the correct order to close the database resource?What R 1


should be the correct order to close the database resource?

Connection, Statements, and then ResultSet

ResultSet, Connection, and then Statements

Statements, ResultSet, and then Connection

ResultSet, Statements, and then Connection

Answer: d

Explanation: The golden rule to JDBC connections and statements is to


close in the reverse order of initiation or opening. In addition, the ResultSet
is dependant on the execution of the Statement and the Statement is
dependant on the Connection instance. Hence, the closing should occur in
that order (ResultSet, Statement, and then Connection).

25 A good way to debug JDBC-related problems is to enable???..? R 1

JDBC tracing

Exception handling

Both a and b

Only b

Answer: a

Explanation: The JDBC Driver supports both DriverManager and


DataSource tracing as documented in the JDBC 3.0 API specification. Trace
information consists of JDBC API method entry and exit points with the
corresponding parameter and returns values. DriverManager.setLogWriter
method to send trace messages to a PrintWriter. The trace output contains a
detailed listing of the JDBC activity.

26 Which JDBC driver can be used in servlet and applet both? U 1


ype 3

Type 4

Type 3 and Type 2

Type 3 and Type 4

Answer: d

Explanation: Type 3 driver follows the three-tier approach which is used to


access the databases. The JDBC clients use standard network sockets to
communicate with a middleware application server. In a Type 4 driver, a
pure Java-based driver that communicates directly with the vendor's
database through a socket connection.

27 JDBC-ODBC driver is also known as? R 1

Type 4

Type 3

Type 1

Type 2

Answer: c

Explanation: Type 1 driver is also known as the JDBC-ODBC bridge driver.


It is a database driver implementation that employs the ODBC driver to
connect to the database. The driver converts JDBC method calls into ODBC
function calls.

28 Which of the following driver is the fastest one? U 1

JDBC-ODBC Bridge Driver

Native API Partly Java Driver

Network Protocol Driver

JDBC Net Pure Java Driver

Answer: d

Explanation: JDBC Net pure Java driver (Type 4) is the fastest driver
because it converts the JDBC calls into vendor-specific protocol calls and it
directly interacts with the database.

29 Which of the following is not a type of ResultSet object? U 1


TYPE_FORWARD_ONLY

CONCUR_WRITE_ONLY

TYPE_SCROLL_INSENSITIVE

TYPE_SCROLL_SENSITIVE

Answer: b

Explanation: There are three types of ResultSet object:

TYPE_FORWARD_ONLY: This is the default type and the cursor can only
move forward in the result set.

TYPE_SCROLL_INSENSITIVE: The cursor can move forward and


backward, and the result set is not sensitive to changes made by others to the
database after the result set was created.

TYPE_SCROLL_SENSITIVE: The cursor can move forward and


backward, and the result set is sensitive to changes made by others to the
database after the result set was created.

Based on the concurrency there are two types of ResultSet object.

CONCUR_READ_ONLY: The ResultSet is read-only, this is the default


concurrency type.

CONCUR_UPDATABLE: We can use the ResultSet update method to


update the rows data.

30 What is JDBC Savepoint? R 1

An intermediate or checkpoint in a transaction

A point where we can store queries

A point where the JDBC application starts execution

A memory where we can store transaction

Hide Answer Workspace

Answer: a

Explanation: JDBC Savepoint helps us in creating checkpoints in a


transaction and we can rollback to that particular checkpoint.

31 How many stages are used by Java programmers while using JDBC in their A 1
programs?
3

Answer: d

Explanation: There are following stages in a JDBC program:

Register the driver

Connecting to a database

Preparing SQL statements in Java

Executing the SQL statements on the database

Retrieving the results

Closing the connection

32 Which of the following is the correct to register a JdbcOdbcDriver? U 1

jdbc.odbc.JdbcOdbcDriver obj = new sun.jdbc.odbc.JdbcOdbcDriver();

odbc.JdbcOdbcDriver obj = new sun.odbc.JdbcOdbcDriver();

jdbc.JdbcOdbcDriver obj = new sun.jdbc.JdbcOdbcDriver();

jdbc.odbc.JdbcOdbc obj = new sun.jdbc.odbc.JdbcOdbc();

Answer: a

Explanation: By creating an object to the driver class of the driver software,


we can register the driver. To register the JdbcOdbcDriver of the sun
microsystems, we can create an object to the driver class JdbcOdbcDriver,
as follows:

sun.jdbc.odbc.JdbcOdbcDriver obj = new sun.jdbc.odbc.JdbcOdbcDriver();

33 How many ways to register a driver? A 1

5
Answer: c

Explanation: There are four ways to register a driver:

1. By creating an object of the Driver For example:

sun.jdbc.odbc.JdbcOdbcDriver obj = new sun.jdbc.odbc.JdbcOdbcDriver();

2. By sending the driver class object to the registerDriver() method of the


DriverManager class. For example:

DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());

3. By sending the driver class name directly to the forName() For example:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

4. By using the getProperty() method of the System class. For example:

String dname = System.getProperty("driver");

Class.forName(dname);

If you are using the above method to register the driver, we should have to
specify the driver's name at the time of running the program. The
getProperty() method receives the driver name and stores the driver name
in dname.

We use the following command to provide the driver name at run time:

c:\> java -Ddriver = driverclassname Programname

For example:

c:\> java -Ddriver = sun.jdbc.odbc.JdbcOdbcDriver MyProgram

34 Identify the DSN in the following statement: R 1

DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger")

jdbc

odbc

scott

oradsn

Answer: d
Explanation: Data Source Name (DSN) is a name given to the database to
identify it in the Java program. The DSN is linked with the actual location of
the database.

35 Which statement is correct if we want to connect the Oracle database using U 1


the thin driver provided by Oracle Corp.?

getConnection("jdbc::thin@localhost:1521:oracle", "scott", "tiger");

getConnection("jdbc:thin@localhost:1521:oracle", "scott", "tiger");

getConnection("jdbc::thin@localhost:1522:oracle", "scott", "tiger");

getConnection("jdbc::oracle@localhost:1521:thin", "scott", "tiger");

Answer: a

Explanation: We use the following statement to connect Oracle database


using the thin driver.

DriverManager.getConnection("jdbc::thin@localhost:1521:oracle", "scott",
"tiger");

36 What are the types of ResultSet in JDBC? R 1

Forward ResultSet

Scrollable ResultSet

Only a

Both a and b

Answer: d

Explanation: JDBC provides only two types of ResultSets: Forward and


Scrollable ResultSet.

37 What is blob in the following statement? R 1

create table profilepic(photo blob);

Variable

Object

Data type

Keyword

Answer: c
Explanation: SQL offers BLOB (Binary Large OBject) data type to store
image files like .gif or .jpg or jpeg into the database table.

38 Which data type is used to store files in the database table? U 1

BLOB

CLOB

File

Both a and b

Answer: b

Explanation: To store a large volume of data such as text file into a table, we
use CLOB (Character Large OBject) data type of SQL.

39 DatabaseMetaData interface is used to get?????..? R 1

Comprehensive information about the database as a whole.

Comprehensive information about the table as a whole.

Comprehensive information about the column as a whole.

Both b and c

Answer: a

Explanation: DatabaseMetaData is an interface that is used to get


Comprehensive information about the database as a whole. It is
implemented by driver vendors to let users know the capabilities of a DBMS
in combination with the JDBC driver that is used with it.

40 Which of the following driver converts the JDBC calls into database- U 1
specific calls?

JDBC-ODBC Bridge Driver (Type 1)

Native API-partly Java Driver (Type 2)

Net Protocol-pure Java Driver (Type 3)

Native Protocol-pure Java Driver (Type 4)

Answer: b

Explanation: Type 2 driver converts JDBC calls into database-specific calls


with the help of vendor database library. It directly communicates with the
database server.
41 Are ResultSets updateable? R 1

Yes, but only if we call the method openCursor() on the ResultSet and if the
driver and database support this option.

Yes, but only if we indicate a concurrency strategy when executing the


statement, and if the driver and database support this option.

Yes, but only if the ResultSet is an object of class UpdateableResultSet and


if the driver and database support this option.

No, ResultSets are never updateable. We must explicitly execute a DML


statement to change the data in the underlying database.

Answer: b

Explanation: By default, a ResultSet object is not updatable and its cursor


moves only in the forward direction. If we want to create an updateable
ResultSet object, either we can use
ResultSet.TYPE_SCROLL_INSENSITIVE or the
ResultSet.TYPE_SCROLL_SENSITIVE type, which moves the cursor
forward and backward relative to the current position.

42 Which of the following interface provides the commit() and rollback() U 1


methods?

Statement Interface

ResultSet Interface

Connection Interface

RowSet Interface

Answer: c

Explanation: The connection interface provides the commit() and rollback()


method. The commit() method makes all changes made since the previous
commit/rollback permanent and releases any database locks currently held
by this Connection object. The rollback() method undoes all changes made
in the current transaction and releases any database locks currently held by
this Connection object.

43 How many statement objects can be created using a Connection? A 1

1
3

Multiple

Answer: d

Explanation: Multiple statements can be created and used on the same


connection, but only one resultset at once can be created and used on the
same statement.

44 JDBC API supports____________ and __________ architecture model for A 1


accessing the database.

Two-tier

Three-tier

Both a and b

Only b

Answer: c

Explanation: The JDBC API supports both two-tier and three-tier processing
models for database access. In the two-tier model, a Java application talks
directly to the data source. In the three-tier model, commands are sent to a
"middle tier" of services, which then sends the commands to the data source.

45 Which statement(s) is/ are true about transactions? U 1

i. A transaction is a set of one or more SQL statements that make up a


logical unit of work.

ii. A transaction ends with either a commit or a rollback, depending on


whether there are any problems with data consistency or data concurrency.

iii. A lock is a mechanism that allows two transactions from manipulating


the same data at the same time.

iv. To avoid conflicts during a transaction, a DBMS uses locks, mechanisms


for blocking access by others to the data that is being accessed by the
transaction.

Only i and ii

Only i and iii

Only i, ii, and iv

All the above


Answer: c

Explanation: The statements i, ii, and iv are true about transactions but iii is
not because the lock mechanism prohibits two transactions from
manipulating the same data at the same time.

46 In order to transfer data between a database and an application written in A 1


the Java programming language, the JDBC API provides which of these
methods?

a. Methods on the ResultSet class for retrieving SQL SELECT results as


Java types.

b. Methods on the PreparedStatement class for sending Java types as SQL


statement parameters.

c. Methods on the CallableStatement class for retrieving SQL OUT


parameters as Java types.

d. All mentioned above

Answer: d. All mentioned above

Explanation: transfer data between a database and an application written in


the Java programming language, the JDBC API provides
ResultSet ,PreparedStatement, CallableStatement.

47 The JDBC API has always supported persistent storage of objects defined in U 1
the Java programming language through the methods getObject and
setObject.

a. True

b. False

Answer: a. True

Explanation:he JDBC API has always supported persistent storage of


objects defined in the Java programming language through the methods
getObject and setObject.

48 Which JDBC type represents a "single precision" floating point number that U 1
supports seven digits of mantissa?

REAL

b. DOUBLE
c. FLOAT

d. INTEGER

Answer: a) REAL

Explanation: REAL DBC type represents a "single precision" floating point


number that supports seven digits of mantissa.

49 Which method is used for retrieving streams of both ASCII and Unicode U 1
characters is new in the JDBC 2.0 core API?
a. getCharacterStream

b. getBinaryStream

c. getAsciiStream

d. getUnicodeStream

Answer: a. getCharacterStream

Explanation: getCharacterStream method is used for retrieving streams of


both ASCII and Unicode characters is new in the JDBC 2.0 core API.

50 How many Result sets available with the JDBC 2.0 core API? A 1

a. 2

b. 3

c. 4

d. 5

Answer: b. 3

Explanation: 3 Result sets available with the JDBC 2.0 core API.

51 Abbreviate the term UDA? R 1

a. Unified Data Access

b. Universal Data Access

c. Universal Digital Access

d. Uniform Data Access


Answer: b. Universal Data Access

Explanation: UDA is the Universal Data Access.

52 The performance of the application will be faster if you use R 1


PreparedStatement interface because query is compiled only once.
a. True

b. False

Answer: a. True

Explanation: The performance of the application will be faster if you use


PreparedStatement interface because query is compiled only once.

53 Which method Drops all changes made since the previous U 1


commit/rollback?

a. public void rollback()

b. public void commit()

c. public void close()

d. public Statement createStatement()

Answer: a. public void rollback()

Explanation: public void rollback() method Drops all changes made since
the previous commit/rollback.

54 The intent is for JDBC drivers to implement non scrollable result sets using U 1
the support provided by the underlying database systems.

a. True

b.False

Answer: b. False

Explanation:The intent is for JDBC drivers to implement scrollable result


sets using the support provided by the underlying database systems.

55 Which methods returns a stream that simply provides the raw bytes from the U 1
database without any conversion?
a. getCharacterStream

b. getBinaryStream

c. getAsciiStream

d. getUnicodeStream

Answer: b. getBinaryStream

Explanation: getBinaryStream methods returns a stream that simply


provides the raw bytes from the database without any conversion.

56 The ACID properties does not describes the transaction management well. U 1
a. True

b. False

Answer: b. False

Explanation: he ACID properties describes the transaction management


well.

57 Which method is used to establish the connection with the specified url in a U 1
Driver Manager class?
a. public static void registerDriver(Driver driver)

b. public static void deregisterDriver(Driver driver)

c. public static Connection getConnection(String url)

d. public static Connection getConnection(String url,String userName,String


password)

Answer: c. public static Connection getConnection(String url)

Explanation: public static Connection getConnection(String url) method is


used to establish the connection with the specified url in a Driver Manager
class.

58 Which Indicates a result set that cannot be updated programmatically in U 1


concurrency?

a. CONCUR_UPDATABLE

b. CONCUR_READ_ONLY

c. All of the above


d. None of the above

Answer: b. CONCUR_READ_ONLY

Explanation: CONCUR_READ_ONLY indicates a result set that cannot be


updated programmatically in concurrency.

59 Which driver Network connection is indirect that a JDBC client makes to a U 1


middleware process that acts as a bridge to the DBMS server?
a. JDBC-Net

b. JDBC-ODBC bridge

c. Native API as basis

d. Native protocol as basis

Answer: a)JDBC-Net

Explanation: JDBC-Net driver Network connection is indirect that a JDBC


client makes to a middleware process that acts as a bridge to the DBMS
server.

60 JDBC RowSet is the wrapper of ResultSet,It holds tabular data like U 1


ResultSet but it is easy and flexible to use.

a. True

b. False

Answer: a. True

Explanation: JDBC RowSet is the wrapper of ResultSet,It holds tabular data


like ResultSet but it is easy and flexible to use.

61 Which kind of driver converts JDBC calls into calls on the client API for U 1
Oracle, Sybase, Informix, IBM DB2, or other DBMS?

a. JDBC-ODBC bridge plus ODBC driver

b. Native-API partly-Java driver

c. JDBC-Net pure Java driver

d. Native-protocol pure Java driver

Answer: b. Native-API partly-Java driver


Explanation: Native-API partly-Java driver converts JDBC calls into calls
on the client API for Oracle, Sybase, Informix, IBM DB2, or other DBMS.

62 Which interfaces provide methods for batch processing in JDBC? U 1

a. java.sql.Statement

b. java.sql.PreparedStatement

c. All the above

d. None of the above

Answer: c. All the above

Explanation: java.sql.Statement interfaces provide methods for batch


processing in JDBC.

63 Which is used to call the stored procedures and functions? U 1

a. CallableStatement Interface

b. PreparedStatement Interface

c. All the above

d. None of the above

Answer: a)CallableStatement Interface

Explanation: CallableStatement Interface is used to call the stored


procedures and functions.

64 In which of the following type of ResultSet, the cursor can only move U 1
forward in the result set?

A - ResultSet.TYPE_FORWARD_ONLY

B - ResultSet.TYPE_SCROLL_INSENSITIVE

C - ResultSet.TYPE_SCROLL_SENSITIVE

D - None of the above.

Answer : A

Explanation: ResultSet.TYPE_FORWARD_ONLY: The cursor can only


move forward in the result set.
65 Which of the following type of JDBC driver, uses database native protocol? U 1

A - JDBC-ODBC Bridge plus ODBC driver

B - Native-API, partly Java driver

C - JDBC-Net, pure Java driver

D - Native-protocol, pure Java driver

Answer : D

Explanation: Native-protocol, pure Java driver, uses database native


protocol.

66 Which of the following is not a valid type of statement in JDBC? U 1

A - Statement

B - PreparedStatement

C - CallableStatement

D - QueryStatement

Answer : D

Explanation:QueryStatement is not a valid type of statement in JDBC.

67 Which of the following is correct about PreparedStatement? U 1

A - PreparedStatement allows mapping different requests with same


prepared statement but different arguments to execute the same execution
plan.

B - Prepared statements are more secure because they use bind variables,
which can prevent SQL injection attack.

C - Both of the above.

D - None of the above.

Answer : C

Explanation: PreparedStatement allows mapping different requests with


same prepared statement but different arguments to execute the same
execution plan. Prepared statements are more secure because they use bind
variables, which can prevent SQL injection attack.

68 How does JDBC handle the data types of Java and database? A 1
A - The JDBC driver converts the Java data type to the appropriate JDBC
type before sending it to the database.

B - It uses a default mapping for most data types.

C - Both of the above.

D - None of the above.

Answer : C

Explanation:The JDBC driver converts the Java data type to the appropriate
JDBC type before sending it to the database. It uses a default mapping for
most data types. For example, a Java int is converted to an SQL INTEGER.

69 Which of the following is correct about connection pooling? U 1

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: If you use an application server like WebLogic, WebSphere,


jBoss, Tomcat. , then your application server provides the facilities to
configure for connection pooling. If you are not using an application server
then components like Apache Commons DBCP Component can be used.

70 Which of the following is correct about setFetchSize(int)? U 1

A - setFetchSize(int) defines the number of rows that will be read from the
database when the ResultSet needs more rows.

B - setFetchSize(int) affects how the database returns the ResultSet data.

C - Both of the above.

D - None of the above.

Answer : C

Explanation:setMaxRows(int) method of the ResultSet specifies how many


rows a ResultSet can contain at a time. setMaxRows(int) affects the client
side JDBC object.
71 Which of the following is true about 'dirty read'? U 1

A - In typical database transactions, say one transaction reads and changes


the value while the second transaction reads the value before committing or
rolling back by the first transaction. This reading process is called as 'dirty
read'.

B - There is always a chance that the first transaction might rollback the
change which causes the second transaction reads an invalid value.

C - Both of the above.

D - None of the above.

Answer : C

Explanation: In typical database transactions, say one transaction reads and


changes the value while the second transaction reads the value before
committing or rolling back by the first transaction. This reading process is
called as 'dirty read'. Because there is always a chance that the first
transaction might rollback the change which causes the second transaction
reads an invalid value.

72 New drivers can be plugged-in to the JDBC API without changing the client U 1
code.

A - true

B - false

Answer : A

Explanation: New drivers can be plugged-in to the JDBC API without


changing the client code.

73 JDBC Version 4 introduced support for retrieving automatically generated U 1


keys after executing an INSERT statement. Which method is used to
retrieve the generated keys?

a) executeQuery()

b) getGeneratedKeys()

c) executeUpdate()

d) getResultSet()

Answer: b) getGeneratedKeys()
Explanation: The getGeneratedKeys() method in JDBC Version 4 is used to
retrieve the automatically generated keys after executing an INSERT
statement.

74 JDBC Version 4 introduced a new feature called "Scrollable Result Sets." U 1


What is the purpose of scrollable result sets?

a) To allow bidirectional traversal of the result set

b) To fetch only a subset of rows from the result set

c) To provide metadata information about the result set

d) To handle batch processing of SQL statements

Answer: a) To allow bidirectional traversal of the result set

Explanation: Scrollable Result Sets in JDBC Version 4 allow bidirectional


traversal of the result set, enabling you to navigate forward and backward
through the rows.

75 Which of the following is a new feature introduced in JDBC Version 4? U 1

a) Connection pooling

b) Distributed transactions

c) Row-level locking

d) Automatic driver loading and registration

Answer: d) Automatic driver loading and registration

Explanation:JDBC Version 4 introduced automatic driver loading and


registration, eliminating the need for explicit driver class loading and
registration using Class.forName().

76 Which of the following is more efficient than a Statement due to the pre- U 1
compilation of SQL?

A. Statement

B. PreparedStatement

C. CallableStatement

D. None of the above.

Answer: B. PreparedStatement
Explanation: The PreparedStatement is more efficient than
the Statement due to the pre-compilation of SQL.

77 What is the correct order to close database resources? R 1

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. ResultSet then Statement then Connection

Explanation: When manually closing database resources, they should be


closed in the reverse order from which they were opened. This means that
the ResultSet object is closed before the Statement object and the Statement
object is closed before the Connection object. This makes Option B the
answer.

78 Which of these obtains a Connection? U 1

A. Connection.getConnection(url)

B. Driver.getConnection(url)

C. DriverManager.getConnection(url)

D. new Connection(url)

Answer: C. DriverManager.getConnection(url)

Explanation: Option C is the correct answer because DriverManager is the


class used in JDBC to get a Connection.

79 What must be the first characters of a database URL? R 1

A. db,

B. db:

C. jdbc,

D. jdbc:

Answer: D. jdbc:

Explanation: All JDBC URLs begin with the protocol jdbc followed by a
colon as a delimiter. Option D is the only one that does both of these,
making it the answer.
80 Which JDBC interface is responsible for managing transactions in JDBC? U 1

a) java.sql.Connection

b) java.sql.Statement

c) java.sql.ResultSet

d) java.sql.Transaction

Answer: a) java.sql.Connection

Explanation: The java.sql.Connection interface in JDBC is responsible for


managing transactions. It provides methods for starting, committing, and
rolling back transactions.

81 How do you handle exceptions in JDBC? A 1

a) By using try-catch blocks

b) By using the throws clause in method signatures

c) By using the catch clause in SQL statements

d) By using the throw statement

Answer: a) By using try-catch blocks

Explanation: Exceptions in JDBC can be handled by using try-catch blocks


to catch and handle specific exceptions that may occur during database
operations.

82 What is the purpose of JDBC batch processing? R 1

a) To execute multiple SQL statements in a single transaction

b) To improve performance by reducing network round trips

c) To handle database connection pooling

d) To handle concurrency in multi-threaded applications

Answer: b) To improve performance by reducing network round trips

Explanation: JDBC batch processing is used to improve performance by


reducing network round trips. It allows multiple SQL statements to be
grouped and sent to the database for execution as a batch.

83 Which method is used to execute an SQL query in JDBC? U 1

a) executeQuery()
b) executeUpdate()

c) execute()

d) executeBatch()

Answer: a) executeQuery()

Explanation: The executeQuery() method in JDBC is used to execute an


SQL query and retrieve the result as a ResultSet object.

84 What is the role of java.sql.ResultSet interface in JDBC? 1

a) To establish a connection to the database

b) To execute SQL statements

c) To represent the result of a database query

d) To handle exceptions in JDBC operations

Answer: c) To represent the result of a database query

Explanation: The java.sql.ResultSet interface in JDBC is used to represent


the result of a database query. It provides methods for navigating and
accessing the retrieved data.

85 What is the purpose of a PreparedStatement in JDBC? R 1

a) To execute SQL queries and retrieve results

b) To insert, update, or delete data in a database

c) To retrieve metadata about a database

d) To handle exceptions in JDBC operations

Answer: b) To insert, update, or delete data in a database

Explanation: A PreparedStatement in JDBC is used to execute


parameterized SQL statements for inserting, updating, or deleting data in a
database.

86 Which JDBC driver Type(s) can be used in either applet or servlet code? U 1

A)Both Type 1 and Type 2

B)Both Type 1 and Type 3

C)Both Type 3 and Type 4


D)Type 4 only

Answer: C)Both Type 3 and Type 4

Explanation: Both Type 3 and Type 4 JDBC driver Type(s) can be used in
either applet or servlet code.

87 ________ is an open source DBMS product that runs on UNIX, Linux and U 1
Windows.

MySQL

B)JSP/SQL

C)JDBC/SQL

D)Sun ACCESS

Answer: A) MySQL

Explanation: MySQL is an open source DBMS product that runs on UNIX,


Linux and Windows.

88 What is sent to the user via HTTP, invoked using the HTTP protocol on the R 1
user's computer, and run on the user's computer as an application?

A)Java application

B)Java applet

C) Java servlet

D)None of the above is correct.

Answer: Option B)Java applet

Explanation:Java servlet is invoked via HTTP on the Web server computer


when it responds to requests from a user's Web browser.

89 What MySQL property is used to create a surrogate key in MySQL? R 1

A)UNIQUE

B)SEQUENCE

C)AUTO_INCREMENT
D)None of the above -- Surrogate keys are not implemented in MySQL.

Answer: Option C)AUTO_INCREMENT

Explanation: If you add an extra column to the table to serve

the purpose of the primary key, then such a primary key is known as a
surrogate key. (because this column has been derived from outside the
table).

90 A JSP is transformed into a(n): U 1

A)Java applet.

B)Java servlet.

C)Either 1 or 2 above.

D)Neither 1 nor 2 above.

Answer: B)Java servlet.

Explanation: Every JSP program internally converted into Servlet program.


The servlet lifecycle methods internally execute JSP lifecycle methods.

91 Among the following options choose the one which shows the advantage of U 1
using the JDBC connection pool.

A)Using less memory

B)Better performance

C)Slower performance

D)Using more memory

Answer: B)

Explanation: The advantage of using a JDBC connection pool is better


performance.

92 Among the following which contains date information. U 1

A)java.sql timestamp
B)java.io time

C)java.io.timestamp

D)java.sql.time

Answer: A)

Explanation: java.sql timestamp contains date information.

93 Identify the method of the JDBC process among the following options. R 1

A)remove()

B)deletebatch()

C)setbatch()

D)addbacth()

Answer: D)

Explanation: addbatch() Is the method of JDBC.

94 Identify the class used for connection-less socket programming. R 1

A)Datagram packet

B)Datagram socket

C)Both A and B

D)None of the above

Answer: C)

Explanation: Both datagram packet and datagram socket is used for


connection-less socket programming.

95 Which of the following option leads to the portability and security of Java? U 1

A)Dynamic binding between objects

B)Use of exception handling

C)Bytecode is executed by JVM

D)The applet makes the Java code secure and portable

Answer: C)

Explanation: Bytecode is executed by JVM is the correct answer.


96 What are the major components of the JDBC? R 1

A)DriverManager, Statement, and ResultSet

B)DriverManager, Driver, Connection, Statement, and ResultSet

C)DriverManager, Connection, Statement, and ResultSet

D)DriverManager, Driver, Connection, and Statement

Answer: B)

Explanation: The major components of JDBC are - DriverManager, Driver,


Connection, Statement, and ResultSet.

97 Which is responsible for getting a connection to the database? U 1

A)Connection

B)Statement

C)ResultSet

D) Driver

Answer: D)

Explanation: Driver is responsible for getting a connection to the database.

98 In which file database table configuration is stored? U 1

A).sql

B).ora

C).hbm

D).dbm

Answer: C)

Explanation: Database table configuration file is stored in .hbm

99 Identify the method which is used to find the URL from the cache of httpd. U 1

A)getfromcache()

B)findfromcache()

C)findcache()

D)servefromcache()
Answer: D)

Explanation: servefromcache() is used to find the URL from the cache of


httpd.

100 Which of the following examples of application servers? U 1

A)JBoss

B)Tomcat

C)Apache

D)WebLogic

Answer: A)

Explanation: JBoss is an example of an application server

You might also like