UNIT - IV Interacting With Database CO:-4 Develop A Program Using Database MCQ Question Bank
UNIT - IV Interacting With Database CO:-4 Develop A Program Using Database MCQ Question Bank
Answer: d
Explanation: java.util.date contains both date and time. Whereas,
java.sql.date contains only date.
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.
Answer: a
Explanation: java.sql.Time contains only time. Whereas,
java.sql.TimeStamp contains both time and date.
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.
Answer: c
Explanation: CallableStatement is used in JDBC to call stored procedure
from Java program.
Answer: a
Explanation: setMaxRows(int i) method is used to limit the number of rows
that the database returns from the query.
Explanation:
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.
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.
Answer: b
executeResult()
executeQuery()
executeUpdate()
execute()
Answer: c
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:
getConnection()
prepareCall()
executeUpdate()
executeQuery()
Answer: A
getConnection()
registerDriver()
forName()
Both b and c
Answer: d
ParameterizedStatement
PreparedStatement
Answer: b
Statement
PreparedStatement
QueryStatement
CallableStatement
Answer: c
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
Answer: b
Answer: d
JDBC tracing
Exception handling
Both a and b
Only b
Answer: a
Type 4
Answer: d
Type 4
Type 3
Type 1
Type 2
Answer: c
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.
CONCUR_WRITE_ONLY
TYPE_SCROLL_INSENSITIVE
TYPE_SCROLL_SENSITIVE
Answer: b
TYPE_FORWARD_ONLY: This is the default type and the cursor can only
move forward in the result set.
Answer: a
31 How many stages are used by Java programmers while using JDBC in their A 1
programs?
3
Answer: d
Connecting to a database
Answer: a
5
Answer: c
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");
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:
For example:
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.
Answer: a
DriverManager.getConnection("jdbc::thin@localhost:1521:oracle", "scott",
"tiger");
Forward ResultSet
Scrollable ResultSet
Only a
Both a and b
Answer: d
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.
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.
Both b and c
Answer: a
40 Which of the following driver converts the JDBC calls into database- U 1
specific calls?
Answer: b
Yes, but only if we call the method openCursor() on the ResultSet and if the
driver and database support this option.
Answer: b
Statement Interface
ResultSet Interface
Connection Interface
RowSet Interface
Answer: c
1
3
Multiple
Answer: d
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.
Only i and ii
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.
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
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
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
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.
b. False
Answer: a. True
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
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
56 The ACID properties does not describes the transaction management well. U 1
a. True
b. False
Answer: b. False
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)
a. CONCUR_UPDATABLE
b. CONCUR_READ_ONLY
Answer: b. CONCUR_READ_ONLY
b. JDBC-ODBC bridge
Answer: a)JDBC-Net
a. True
b. False
Answer: a. True
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. java.sql.Statement
b. java.sql.PreparedStatement
a. CallableStatement Interface
b. PreparedStatement Interface
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
Answer : A
Answer : D
A - Statement
B - PreparedStatement
C - CallableStatement
D - QueryStatement
Answer : D
B - Prepared statements are more secure because they use bind variables,
which can prevent SQL injection attack.
Answer : C
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.
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.
Answer : C
A - setFetchSize(int) defines the number of rows that will be read from the
database when the ResultSet needs more rows.
Answer : C
B - There is always a chance that the first transaction might rollback the
change which causes the second transaction reads an invalid value.
Answer : C
72 New drivers can be plugged-in to the JDBC API without changing the client U 1
code.
A - true
B - false
Answer : A
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.
a) Connection pooling
b) Distributed transactions
c) Row-level locking
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
Answer: B. PreparedStatement
Explanation: The PreparedStatement is more efficient than
the Statement due to the pre-compilation of SQL.
A. Connection.getConnection(url)
B. Driver.getConnection(url)
C. DriverManager.getConnection(url)
D. new Connection(url)
Answer: C. DriverManager.getConnection(url)
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
a) executeQuery()
b) executeUpdate()
c) execute()
d) executeBatch()
Answer: a) executeQuery()
86 Which JDBC driver Type(s) can be used in either applet or servlet code? U 1
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
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
A)UNIQUE
B)SEQUENCE
C)AUTO_INCREMENT
D)None of the above -- Surrogate keys are not implemented in MySQL.
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).
A)Java applet.
B)Java servlet.
C)Either 1 or 2 above.
91 Among the following options choose the one which shows the advantage of U 1
using the JDBC connection pool.
B)Better performance
C)Slower performance
Answer: B)
A)java.sql timestamp
B)java.io time
C)java.io.timestamp
D)java.sql.time
Answer: A)
93 Identify the method of the JDBC process among the following options. R 1
A)remove()
B)deletebatch()
C)setbatch()
D)addbacth()
Answer: D)
A)Datagram packet
B)Datagram socket
C)Both A and B
Answer: C)
95 Which of the following option leads to the portability and security of Java? U 1
Answer: C)
Answer: B)
A)Connection
B)Statement
C)ResultSet
D) Driver
Answer: D)
A).sql
B).ora
C).hbm
D).dbm
Answer: C)
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)
A)JBoss
B)Tomcat
C)Apache
D)WebLogic
Answer: A)