To develop any JDBC application, we follow the following five steps which are as follows:
We know database driver is a software which is written according to the JDBC API. There are different ways to register a driver. Here I have presented one way by considering Oracle database that is to send the driver class name directly to forName() method as :
Note: Here we are using type-4 (thin) driver.
The getConnection() method of DriverManager class is used to establish connection with the database.
After connecting to the database, we prepare SQL statements by creating an object of type Statement or PreparedStatement or CallableStatement (an interface available in java.sql package) for performing different operations on the database. For example:
Here by the createStatement() method, we prepare the SQL statement which is assigned in Statement object st.
After executing this statement, the results are stored in rs.
By closing connection object statement and ResultSet will be closed automatically. The close() method of Connection interface is used to close the connection.