Java Database Connectivity (JDBC) is an application programming interface (API) for the programming language Java, which defines how a client may access a database. It is a Java-based data access technology used for Java database connectivity. It is part of the Java Standard Edition platform, from Oracle Corporation
Using JDBC to connect to a database
The steps for connecting to a database with JDBC are as follows:
- Install or locate the database you want to access.
- Include the JDBC library.
- Ensure the JDBC driver you need is on your classpath.
- Use the JDBC library to obtain a connection to the database.
- Use the connection to issue SQL commands.
- Close the connection when you're finished.
Each of these imports provides access to a class that facilitates the standard Java database connection:
- Connection represents the connection to the database.
- DriverManager obtains the connection to the database. (Another option is DataSource, used for connection pooling. )
- SQLException handles SQL errors between the Java application and the database.
- ResultSet and Statement model the data result sets and SQL statements.