Java Database Connectivity (JDBC) is a Java-based API that enables Java applications to interact with a variety of databases. It provides methods to connect to a database, execute SQL queries, and retrieve results.
Key Components of JDBC
- JDBC Driver: A software component that enables Java applications to interact with a database. Different databases have different drivers (e.g., MySQL, PostgreSQL, Oracle).
- DriverManager: A class that manages a list of database drivers. It establishes a connection to the database.
- Connection: An interface that represents a connection to a specific database.
- Statement: An interface used to execute SQL queries against the database. It comes in three types:
- Statement: For executing simple SQL statements.
- PreparedStatement: For executing precompiled SQL statements with parameters.
- CallableStatement: For executing stored procedures in the database.
- ResultSet: An interface that represents the result set of a query. It allows you to retrieve data from the database.
- SQLException: An exception class that handles any database access errors.