Discover Java Database Connectivity (JDBC) through this comprehensive set of 30 MCQs. Perfect for developers looking to enhance their database integration skills, this collection covers JDBC basics, drivers, connections, SQL queries, prepared statements, and batch processing techniques.
MCQs
1-10: Introduction to JDBC
What does JDBC stand for in Java?
A) Java Database Communication
B) Java Data Connector
C) Java Database Connectivity
D) Java Database Class
Which of the following is a major purpose of JDBC?
A) To connect Java applications to various databases
B) To enhance Java user interfaces
C) To speed up Java applications
D) To manage memory in Java applications
What is the first step to establish a connection to a database in JDBC?
A) Load the JDBC driver
B) Execute an SQL query
C) Close the connection
D) Set the database credentials
Which of the following methods is used to create a database connection in JDBC?
A) DriverManager.getConnection()
B) Connection.openConnection()
C) JDBC.connect()
D) Database.connect()
Which class is used to manage the database connection in JDBC?
A) Statement
B) Connection
C) Driver
D) ResultSet
Which interface provides methods to establish a connection to a database in JDBC?
A) Connection
B) DriverManager
C) Statement
D) PreparedStatement
Which method is used to load a JDBC driver class in Java?
A) Class.forName()
B) Driver.load()
C) getClass()
D) JDBC.loadDriver()
Which of the following can JDBC be used for?
A) Managing database connections
B) Performing CRUD operations
C) Executing SQL queries
D) All of the above
In JDBC, what type of object is used to execute SQL queries?
A) Statement
B) ResultSet
C) Connection
D) CallableStatement
What type of JDBC object is used to execute stored procedures?
A) CallableStatement
B) PreparedStatement
C) Statement
D) ResultSet
11-15: JDBC Drivers and Connections
What is the purpose of a JDBC driver?
A) To handle communication between Java and the database
B) To store database credentials
C) To execute SQL queries
D) To display results in the UI
Which of the following is a type of JDBC driver?
A) Type 1: JDBC-ODBC Bridge
B) Type 2: Native-API Driver
C) Type 3: Network Protocol Driver
D) All of the above
Which JDBC driver is suitable for direct connection to the database server using native API calls?
A) Type 1 Driver
B) Type 2 Driver
C) Type 3 Driver
D) Type 4 Driver
Which method in the Connection interface is used to create a Statement object?
A) createStatement()
B) prepareStatement()
C) setStatement()
D) newStatement()
What is the correct syntax to register a JDBC driver in Java?
A) DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
B) Driver.registerDriver(com.mysql.cj.jdbc.Driver);
C) Connection.registerDriver(com.mysql.cj.jdbc.Driver);