Create Database Connection in Hibernate in MyEclipse 8.5 (on the name "SNRaoConnection")
Note: For beginners, it is advised to read first Hibernate Tutorial for Beginners – JDBC vs Hibernate.
We know Hibernate internally uses JDBC. So, give to the Hibernate all the particulars of the database to connect. This is what we are doing now here in this tutorial Create Database Connection Hibernate.
Before going into the actual Student program, let us create one database connection. This connection can be used by any Hibernate program in future. Alternatively, you also can create a database connection for each Hibernate program separately (I avoided this for unnecessary extra repeated work).
Here I am using MyEclipse instead of Eclipse as MyEclipse comes with implicitly added the Jar files of Hibernate and Spring.
1. Choose "MyEclipse Database Explorer" from "Perspectives" (literal meaning of perspective is view). Perspectives option is available on the right top corner of MyEclipse window.
Now observe of the window changes in MyEclipse.
2. You see a left panel, named "DB Broswer" with default "MyEclipse Derby" database. We do not have any work with "MyEclipse Derby" as we are using Oracle. Right click on the empty space of "DB Browser" and select "New".
You see a window like the following with "Database Driver" dialog box.
3. Fill up the each text field of "Database Driver" wizard as follows:
Driver template: From the drop down list choose "Oracle (thin)" option. It means you are using Type 4 driver to connect to Oracle database.
Driver name: SNRaoConnection. Here, give any name you like and infact this name is used, in future, from any Hibernate program to connect to database.
Connection URL: By default you get like this:
replace as follows
Perhaps, you might have used the same in your JDBC programs earlier where orcl is the Oracle service name and 1521 is the port number of Oracle server.
User name: scott
Driver Jars: Click "Add Jars" button. It gets you windows file "Open" dialog box. Choose ojdbc.14.jar file from your hard disk. Now it is shown in the text area.
Driver classname: When you choose ojdbc14.jar file, this text field automatically filled with oracle.jdbc.driver.OracleDriver.
Now your job is over. Let us check the particulars given by you are correct or not. For this click over the "Test Drive" button and fill up the password as tiger. You must get a message "successfully connected".
Now what is done is you have created a general database connection on the name of SNRaoConnection and it will be used in our all future programs.