JDBC Online Quiz

Welcome to our beginner-level JDBC (Java Database Connectivity) quiz! This quiz is crafted for those new to using JDBC, a Java API that allows Java programs to connect to databases. Over the next 25 multiple-choice questions, you'll test your knowledge on the basics of JDBC, including its components, usage, and how it interacts with databases. Whether you're just starting your journey in database programming or need to solidify your understanding of JDBC, this quiz will help guide you through the fundamental concepts.

1. What does JDBC stand for?

a) Java Database Connectivity
b) Java Data Connection
c) Java Development Connection
d) Java Database Control

2. What is the primary purpose of JDBC?

a) To provide an interface for Java applications to interact with databases
b) To create databases in Java
c) To replace SQL
d) To store data in Java objects

3. Which component in JDBC is responsible for executing SQL commands?

a) DriverManager
b) Connection
c) Statement
d) ResultSet

4. What does the Connection interface in JDBC do?

a) Connects to the database
b) Executes SQL queries
c) Manages result sets
d) Handles transactions

5. Which method would you use to retrieve data from a database in JDBC?

a) executeUpdate()
b) executeQuery()
c) execute()
d) updateQuery()

6. How do you load a JDBC driver?

a) Using the DriverManager.load() method
b) By calling Class.forName()
c) By using Driver.loadDriver()
d) JDBC drivers are automatically loaded

7. What does the DriverManager class do?

a) Connects directly to the database
b) Manages the list of database drivers
c) Sends SQL commands to the database
d) Receives results from the database

8. What type of SQL statements return a ResultSet in JDBC?

a) Data Definition Language (DDL) statements
b) Data Manipulation Language (DML) statements
c) SELECT statements
d) INSERT statements

9. What is a PreparedStatement in JDBC?

a) A statement that is formatted before being used
b) A reusable, precompiled statement
c) A statement used only for SQL commands
d) A statement that prevents SQL injection

10. How do transactions in JDBC work?

a) They are managed by the SQL server
b) They are automatically committed by the JDBC driver
c) They allow multiple operations to be treated as a single logical unit
d) They execute each SQL command separately

11. Which JDBC component represents a cursor pointing to its current row of data?

a) Connection
b) DriverManager
c) ResultSet
d) Statement

12. What does commit() do in a JDBC connection?

a) Saves changes made during the current transaction
b) Updates the database structure
c) Commits SQL commands to be executed
d) Starts a new transaction

13. How can you roll back a transaction in JDBC?

a) Using the rollback() method on the Connection object
b) By deleting the Statement object
c) Using the undo() method on the ResultSet object
d) Transactions cannot be rolled back

14. What does JDBC API use to pass SQL commands to the database?

a) Java commands
b) Direct method calls
c) SQL strings
d) XML files

15. What is the use of setAutoCommit() method in JDBC?

a) It allows the database to use automatic SQL commands.
b) It prevents the JDBC driver from loading.
c) It sets the commit behavior of the connection.
d) It configures the SQL command structure.

16. Which interface do you use to execute SQL stored procedures?

a) Statement
b) CallableStatement
c) PreparedStatement
d) ExecuteStatement

17. What should you always do after finishing with a ResultSet?

a) Leave it open for future queries
b) Call the refresh() method
c) Close it
d) Nothing, JDBC handles it automatically

18. Which method retrieves data from a ResultSet object?

a) getData()
b) retrieve()
c) fetch()
d) getXXX()

19. In JDBC, what does the XXX in method names like getXXX() and setXXX() represent?

a) A placeholder for data types
b) A specific SQL command
c) A database table name
d) A configuration setting

20. What is JDBC metadata?

a) Data about the structure of the database, such as tables and columns
b) Information about the JDBC driver version
c) Metadata used for setting up connections
d) Data that describes other data in XML format

21. Which of these is NOT a function of the Connection interface?

a) Managing transactions
b) Sending SQL commands to the database
c) Parsing XML files
d) Creating Statement objects

22. What is a JDBC Driver?

a) A type of SQL command
b) A database user credential
c) A software component that enables Java applications to interact with a database
d) A type of database

23. How do you update data in a database using JDBC?

a) Using the executeQuery() method
b) Using the executeUpdate() method
c) Using the execute() method
d) Using the update() method

24. Which of the following best describes the type of driver that converts JDBC calls into database-specific calls?

a) Type 1 driver
b) Type 2 driver
c) Type 3 driver
d) Type 4 driver

25. What advantage does PreparedStatement have over Statement?

a) Faster execution
b) Does not require an SQL query
c) Allows execution of multiple queries simultaneously
d) Automatically closes the database connection