wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes how to connect to a database in hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "how to connect to a database in hibernate" Watch "how to connect to a database in hibernate" New topic
Author

how to connect to a database in hibernate

Rituparna Duttagupta
Ranch Hand

Joined: Feb 08, 2011
Posts: 55

Hello everybody,
I am new to hibernate. In my earlier projects where i have created ODBC datasources and connect to it through JdbcOdbcDriver.
Now, how to create a database connectivity in hibernate?
I am using SQL 2008 database and Netbeans 6.9.1 IDE.
Someone please help me.


With regards,
rituparna
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You should never use the JDBC-ODBC bridge unless there is no choice (i.e. its Access you are using)

You can either configure Hibernate to use an already configured DataSource, or you can get it to use the DriverManager. The example in the documentation shows the later. Microsoft supply a type 4 JDBC driver (check MSDN) or jTDS can be used.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Rituparna Duttagupta
Ranch Hand

Joined: Feb 08, 2011
Posts: 55

documentation link is not opening at the moment.
In the book "Professional Hibernate" there is some code like

Let me clear some doubts....
1. is the username and password that i use to connect to a server, right?

2.here, driver_class means the name of the driver class??

3.what url is this? the url to locate the datasource/database?

4.
here DatabaseName=test, is that means that the name of the database here is 'test', that means if I wish to connect to a database say, tutorial, then i'll write
DatabaseName=tutorial, is that so?

then, what is that url points to, in the hibernate.connection.url?

And, at last, where should i include all this code?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


documentation link is not opening at the moment.

Works fine for me. I'd check your network settings - working with Hibernate without the documentation is not going to be fun.

That code you posted looks out of date. I would get the documentation first and foremost before going to a book.

Questions 1 and 2: yes.

Question 3: The JDBC driver url (as defined by your driver's documentation)

Question 4: This is driver specific (i.e. nothing to do with Hibernate). Your JDBC docs will tell you, but probably is the answer.

You should include this in your configuration for Hibernate. That can be a properties file, a config XML file or code. The section on configuration in the documentation is where you need to look.
Rituparna Duttagupta
Ranch Hand

Joined: Feb 08, 2011
Posts: 55

Thanks for reply Paul,
I don't know, may be there's some network problem, that's why the link is not opening.
Is there a separate driver in SQL to connect to Hibernate? if yes, where could i get it?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

JDBC drivers are nothing to do with Hibernate as such, these are part of JDBC (that Hibernate uses). You can get a driver for SQL Server from MSDN or google for jTDS.
Rituparna Duttagupta
Ranch Hand

Joined: Feb 08, 2011
Posts: 55

thanks Paul, i am getting the documentation link now.
i have download the jTDS zip file, in there home page they said to "just drop the jar in your application's classpath". it's not getting clear to me, what does this classpath means?
I am using netbeans, so where should i place the jTDS jar file??
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Classpath is a fairly important concept in Java. Have a read of this.
Rituparna Duttagupta
Ranch Hand

Joined: Feb 08, 2011
Posts: 55

My question is that..
whether i should set the classpath for jTDS.jar in the same way as we set the classpath for jdk?
and can i access that from the command prompt, but i use netbeans, can it be useful for that also??
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to connect to a database in hibernate