Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

JDBC MCQs

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Chapter : JDBC ODBC

1. Which of the following is correct about driver interface of JDBC?


A - JDBC driver is an interface enabling a Java application to interact with a database.
B -The JDBC driver gives out the connection to the database and implements the protocol
for transferring the query and result between client and database.
C - Both of the above.
D - none of the above.
Ans c

2.In which of the following type of ResultSet, the cursor can only move 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.
Ans A

3. Which of the following is correct about PreparedStatement?


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.
Ans c
4.  How does JDBC handle the data types of Java and database?
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.
Ans c

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


A - Application server like WebLogic, WebSphere, jBoss and Tomcat provides the facilities
to configure connection pooling.
B - components like Apache Commons DBCP Component can be used to configure
connection pooling.
C - Both of the above.
D - None of the above.
Ans c

6.Which of the following is first step to create a JDBC application?


A - Import packages containing the JDBC classes needed for database programming.
B - Register the JDBC driver, so that you can open a communications channel with the
database.
C - Open a connection using the DriverManager.getConnection () method.
D - Execute a query using an object of type Statement.
Ans A

7. A connected RowSet Object is permanent in nature. It doesn't terminate until the


application is terminated.
A - true
B - false
Ans A
8.Which of the following is a Metadata interfaces of JDBC?
A - DatabaseMetaData
B - ResultSetMetaData
C - Both of the above.
D - None of the above.
Ans C

9. Which packages contain the JDBC classes?


a. java.jdbc and javax.jdbc
b. java.jdbc and java.jdbc.sql
c. java.sql and javax.sql
d. java.rdb and javax.rdb
Ans:c

10. Which type of Statement can execute parameterized queries?


a. PreparedStatement
b. ParameterizedStatement
c. ParameterizedStatement and CallableStatement
d. All kinds of Statements (i.e. which implement a sub interface of Statement)
Ans: a

11. How can you execute DML statements (i.e. insert, delete, update) in the database?
a. By making use of the InsertStatement, DeleteStatement or UpdateStatement classes
b. By invoking the execute(…) or executeUpdate(…) method of a normal Statement object
or a sub-interface object thereof
c. By invoking the executeInsert(…), executeDelete(…) or executeUpdate(…) methods of the
DataModificationStatement object
d. By making use of the execute(…) statement of the DataModificationStatement object
Ans: b

12.  Are ResultSets updateable?


a. Yes, but only if you call the method openCursor() on the ResultSet, and if the driver and
database support this option
b. Yes, but only if you indicate a concurrency strategy when executing the statement, and if
the driver and database support this option
c. Yes, but only if the ResultSet is an object of class UpdateableResultSet, and if the driver
and database support thisoption
d. No, ResultSets are never updateable. You must explicitly execute DML statements (i.e.
insert, delete and update) to change the data in the underlying database
Ans: b

13. What statements are correct about JDBC transactions (2 correct answers)?
a. A transaction is a set of successfully executed statements in the database
b. A transaction is finished when commit() or rollback() is called on the Connection object,
c. A transaction is finished when commit() or rollback() is called on the Transaction object
d. A transaction is finished when close() is called on the Connection object.
Ans: d

14. The JDBC-ODBC Bridge supports multiple concurrent open statements per connection?
a. True
b. False
Ans: a

15. Which of the following statements is false as far as different type of statements is
concern in JDBC?
a. Regular Statement
b. Prepared Statement
c. Collable Statement
d. Interim Statement
Ans: d

16. Which of the following methods are needed for loading a database driver in JDBC?
a. registerDriver() method
b. Class.forName()
c. Both A and B
d. getConnection()
Ans: c
17. Which statement is static and synchronized in JDBC API?
a. executeQuery()
b. executeUpdate()
c. getConnection()
d. prepareCall()
Ans: c

18. The JDBC-ODBC bridge is


a. Three tiered
b. Multithreaded
c. Best for any platform
d. All of the above
Ans: b

19. The class java.sql.Timestamp has its super class as


a. java.sql.Time
b. java.util.Date
c. java.util.Time
d. None of the above
Ans: b

20. Which of the following methods finds the maximum number of connections that a
specific driver can obtain?
a. Database.getMaxConnections
b. Connection.getMaxConnections
c. DatabaseMetaData.getMaxConnections
d. ResultSetMetaData.getMaxConnections
Ans: c

21. Are prepared statements actually compiled?


a. Yes, they compiled
b. No, they are bound by the JDBC driver
Ans: a
22. When the message “No Suitable Driver” occurs?
a. When the driver is not registered by Class.forname() method
b. When the user name, password and the database does not match
c. When the JDBC database URL passed is not constructed properly
d. When the type 4 driver is used
Ans: c

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


a. execute()
b. executeQuery()
c. executeUpdate()
d. executeResult()
Ans: c

24. State true or false. Is the JDBC-ODBC bridge multithreaded ?


A. TRUE
B. FALSE
Ans: A

25. ________ is an open source DBMS product that runs on UNIX, Linux and Windows.
A. MySQL
B. JSP/SQL
C. JDBC/SQL
D. Sun ACCESS
Ans: A

26.

You might also like