Getting a database connection error in EJB project

Asked By 240 points N/A Posted on -
qa-featured

I am setting up a web application on my machine. It uses EJB to access the data in a MySQL database. When I attempt to access the website, I get an EJB exception saying, "could not create a connection". I checked all configuration files but they look alright. Please help me to get to the bottom of this problem.

SHARE
Best Answer by MathGirl
Answered By 0 points N/A #91444

Getting a database connection error in EJB project

qa-featured

What is the Java framework you are using? And what is the middleware library you are using?

Answered By 240 points N/A #91445

Getting a database connection error in EJB project

qa-featured

I am using Java Server Faces 2.0 as the web framework. I am using EJB3 with Java Persistence API. I am using the Hibernate JPA libraries as the database abstraction middleware. My development environment is Netbeans and the application server I am using is Glassfish version 3.

Answered By 0 points N/A #91446

Getting a database connection error in EJB project

qa-featured

Thank you for the information. I think the problem might be on the connection pool that is being used by the application. You need to double check the properties in it. Java is case sensitive. Therefore you may need to "double" enter certain properties by mixing up the uppercase and lower case.

Answered By 240 points N/A #91447

Getting a database connection error in EJB project

qa-featured

MathGirl,

What do you mean by "double" entry of the properties? I do not understand.

Answered By 0 points N/A #91448

Getting a database connection error in EJB project

qa-featured

When you look at the properties of a JDBC connection on Glassfish management console, there are properties that have the same name but are typed differently. Depending on the middleware you are using this matters a lot. For example "URL" and "Url" sound the same but they are two entries in the properties section in the connection pool with the same value. I have attached a screenshot to help you understand.

Answered By 0 points N/A #91449

Getting a database connection error in EJB project

qa-featured

Jachim,

You will have to check the JDBC connection JNDI name as well. The JNDI name is hard-coded in the application. The two names should match or EJB will not be able to do a lookup to get database connection. This is a common pitfall when development is done in Windows and deployment is done in Linux.

Answered By 240 points N/A #91450

Getting a database connection error in EJB project

qa-featured

I tried both solutions given by MathGirl and Whiz Boy. Still I get the same problem. Please help!

Best Answer
Best Answer
Answered By 0 points N/A #91451

Getting a database connection error in EJB project

qa-featured

Can you re-check the stack trace of the Glassfish Application server log? You will need to look very closely on the stack trace as it will be very long. Try to see if you can find the root error. It may be along the lines of "SQLException".

Answered By 240 points N/A #91452

Getting a database connection error in EJB project

qa-featured

I checked the log file again. I filtered to SQL Exception. Guess what? I found the bug! The database name is in the wrong case! I fixed it. Now it works! Thank you!

Answered By 0 points N/A #91453

Getting a database connection error in EJB project

qa-featured

As Whiz Boy suggested, you need to be careful when developing in Windows and deploying in Linux! "Case" matters a lot!

Related Questions