To develop any JDBC application, we follow the following five steps which are as follows:
Let’s analyze the above steps:
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 preparing SQL statements, then we execute the SQL statements by executeQuery()or executeUpdate() or execute().
ResultSet rs = rs.executeQuery(“select * from employee”);
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.
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc