Introduction and Life Cycle
Last updated
Last updated
Java™ database connectivity (JDBC) is the JavaSoft specification of a standard application programming interface (API) that allows Java programs to access database management systems. The JDBC API consists of a set of interfaces and classes written in the Java programming language.
Using these standard interfaces and classes, programmers can write applications that connect to databases, send queries written in structured query language (SQL), and process the results.
Since JDBC is a standard specification, one Java program that uses the JDBC API can connect to any database management system (DBMS), as long as a driver exists for that particular DBMS.
A JDBC program comprises the following FIVE steps:
STEP 1: Allocate a Connection
object, for connecting to the database server.
STEP 2: Allocate a Statement
object, under the Connection
created earlier, for holding a SQL command.
STEP 3: Write a SQL query and execute the query, via the Statement
and Connection
created.
STEP 4: Process the query result as ResultSet
. The ResultSet
only for Select Query.
STEP 5: Close the Statement
and Connection
to free up the resources.