Create Database Connection Hibernate

Create Database Connection Hibernate

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.

image

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:

jdbc:oracle:thin:@[:<1521>]:)

replace as follows

jdbc:oracle:thin:@localhost:1521:orcl

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

Password: tiger

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.

4. Testing

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.

5 thoughts on “Create Database Connection Hibernate

  1. vithu

    Sir,
    i have been using mysql for a long time. and never used Oracle Database. in order to follow your hibernate tutorials, i would like to add oracle database. so do i have to install Oracle Database in my computer. it seems (2.5 gb) big.

  2. vithu

    Hello sir,
    Cant we use eclipse for your hibernate examples. What is the different between eclipse and Myeclipse. when i put a search on My eclipse it seems little more advance IDE. so do you suggest to use this IDE in future for all java projects?

Leave a Reply

Your email address will not be published. Required fields are marked *