First, you need to load the JDBC driver. In order to do this you will first have to load the class, which you think is suitable. Then, make the driver instance yourself and simply get it registered with the JDBC driver manager. You will have to name the class once you are registering it and in order to remember the name, simply keep it as ‘Class’. There are several database vendors who will provide you with free JDBC drivers.
In the next step, you have to define the connection URL. After loading the JDBC driver, you need to specify its location. The vendor documentation must be checked for the exact information regarding the connection URL.
Once you have defined the connection URL, it is time for you to establish the connection. You need to pass the URL you have used in the second step, the username which you set in the first step and also the password which you decided once you registered yourself.
Now is your time to create a statement. It is very important to create a statement because this object helps you send queries and commands directly to the database.
Since you have already created a statement, it is time for you to check whether it is working. In order to do that, you must try and send a query to the database. Once you send the query, or even an update, you will notice that it will return an object of type Result Set.
Once the results are at hand, it is time for you to process them. They will be in the form of a table, and you can start reading them by considering one row at a time. Simply display the results by using the “getString” not considering the actual column type.
Lastly, you must close the connection in order to complete the usage of Java JDBC with a database.