Olete.in
Articles
Mock Tests
🧪 JDBC MCQ Quiz Hub
JDBC Mcq Set 1
Choose a topic to test your knowledge and improve your JDBC skills
1. What are the major components of the JDBC?
DriverManager, Driver, Connection, Statement, and ResultSet
DriverManager, Driver, Connection, and Statement
DriverManager, Statement, and ResultSet
DriverManager, Connection, Statement, and ResultSet
2. Select the packages in which JDBC classes are defined?
jdbc and javax.jdbc
rdb and javax.rdb
jdbc and java.jdbc.sql
sql and javax.sql
3. Thin driver is also known as?
Type 3 Driver
Type-2 Driver
Type-4 Driver
Type-1 Driver
4. What is the correct sequence to create a database connection? i. Import JDBC packages. ii. Open a connection to the database. iii. Load and register the JDBC driver. iv. Execute the statement object and return a query resultset. v. Create a statement object to perform a query. vi. Close the resultset and statement objects. vii. Process the resultset.
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
5. Which of the following method is used to perform DML statements in JDBC?
executeResult()
executeQuery()
executeUpdate()
execute()
6. How many transaction isolation levels provide the JDBC through the Connection interface?
3
4
7
2
7. Which of the following method is static and synchronized in JDBC API?
getConnection()
prepareCall()
executeUpdate()
executeQuery()
8. Which methods are required to load a database driver in JDBC?
getConnection()
registerDriver()
forName()
Both b and c
9. Parameterized queries can be executed by?
ParameterizedStatement
PreparedStatement
CallableStatement and Parameterized Statement
All kinds of Statements
10. Which of the following is not a valid statement in JDBC?
Statement
PreparedStatement
QueryStatement
CallableStatement
11. Identify the isolation level that prevents the dirty in the JDBC Connection class?
TRANSACTION_READABLE_READ
TRANSACTION_READ_COMMITTED
TRANSACTION_READ_UNCOMMITTED
TRANSACTION_NONE
12. What does setAutoCommit(false) do?
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.
13. Stored procedure can be called by using the ????..?
CallableStatement
Statement
CalledStatement
PreparedStatement
14. What should be the correct order to close the database resource?What 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
15. A good way to debug JDBC-related problems is to enable???..?
JDBC tracing
Exception handling
Both a and b
Only b
16. Which JDBC driver can be used in servlet and applet both?
Type 3
Type 4
Type 3 and Type 2
Type 3 and Type 4
17. JDBC-ODBC driver is also known as?
Type 4
Type 3
Type 1
Type 2
18. Which of the following driver is the fastest one?
JDBC-ODBC Bridge Driver
Native API Partly Java Driver
Network Protocol Driver
JDBC Net Pure Java Driver
19. Which of the following is not a type of ResultSet object?
TYPE_FORWARD_ONLY
CONCUR_WRITE_ONLY
TYPE_SCROLL_INSENSITIVE
TYPE_SCROLL_SENSITIVE
20. What is JDBC Savepoint?
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
21. How many stages are used by Java programmers while using JDBC in their programs?
3
2
5
6
22. Which of the following is the correct to register a JdbcOdbcDriver?
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();
23. How many ways to register a driver?
2
3
4
5
24. Identify the DSN in the following statement: DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger")
jdbc
odbc
scott
oradsn
25. Which statement is correct if we want to connect the Oracle database using 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");
26. What are the types of ResultSet in JDBC?
Forward ResultSet
Scrollable ResultSet
Only a
Both a and b
27. What is blob in the following statement? create table profilepic(photo blob);
Variable
Object
Data type
Keyword
28. Which data type is used to store files in the database table?
BLOB
CLOB
File
Both a and b
29. DatabaseMetaData interface is used to get?????..?
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
30. Which of the following driver converts the JDBC calls into database-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)
31. Are ResultSets updateable?
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.
32. Which of the following interface provides the commit() and rollback() methods?
Statement Interface
ResultSet Interface
Connection Interface
RowSet Interface
33. How many statement objects can be created using a Connection?
2
1
3
Multiple
34. JDBC API supports____________ and __________ architecture model for accessing the database.
Two-tier
Three-tier
Both a and b
Only b
35. Which statement(s) is/ are true about transactions? 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
36. Which of the following contains both date and time?
java.io.date
java.sql.date
java.util.date
java.util.dateTime
37. Which of the following is advantage of using JDBC connection pool?
Slow performance
Using more memory
Using less memory
Better performance
38. Which of the following is advantage of using PreparedStatement in Java?
Slow performance
Encourages SQL injection
Prevents SQL injection
More memory usage
39. Which one of the following contains date information?
java.sql.TimeStamp
java.sql.Time
java.io.Time
java.io.TimeStamp
40. Which of the following is used to call stored procedure?
Statement
PreparedStatement
CallableStatment
CalledStatement
41. Which of the following is used to limit the number of rows returned?
setMaxRows(int i)
setMinRows(int i)
getMaxrows(int i)
getMinRows(int i)
42. Which of the following is method of JDBC batch process?
setBatch()
deleteBatch()
removeBatch()
addBatch()
43. Which of the following is used to rollback a JDBC transaction?
rollback()
rollforward()
deleteTransaction()
RemoveTransaction()
44. Which of the following is not a JDBC connection isolation levels?
TRANSACTION_NONE
TRANSACTION_READ_COMMITTED
TRANSACTION_REPEATABLE_READ
TRANSACTION_NONREPEATABLE_READ
45. How constructor can be used for a servlet?
Initialization
Constructor function
Initialization and Constructor function
Setup() method
46. Can servlet class declare constructor with ServletConfig object as an argument?
True
False
all of the above
none of the above
47. What is the difference between servlets and applets? i. Servlets execute on Server; Applets execute on browser ii. Servlets have no GUI; Applet has GUI iii. Servlets creates static web pages; Applets creates dynamic web pages iv. Servlets can handle only a single request; Applet can handle multiple requests
i, ii, iii are correct
i, ii are correct
i, iii are correct
i, ii, iii, iv are correct
48. Which of the following code is used to get an attribute in a HTTP Session object in servlets?
session.getAttribute(String name)
session.alterAttribute(String name)
session.updateAttribute(String name)
session.setAttribute(String name)
49. Which method is used to get three-letter abbreviation for locale’s country in servlets?
Request.getISO3Country()
Locale.getISO3Country()
Response.getISO3Country()
Local.retrieveISO3Country()
50. Which of the following code retrieves the body of the request as binary data?
DataInputStream data = new InputStream()
DataInputStream data = response.getInputStream()
DataInputStream data = request.getInputStream()
DataInputStream data = request.fetchInputStream()
Submit