permaculture playing cards*
The moose likes Struts and the fly likes Database connection problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Database connection problem " Watch "Database connection problem " New topic
Author

Database connection problem

amit sharma
Ranch Hand

Joined: Jul 19, 2006
Posts: 129
I not able to connect to database.My code is

When i check whether datasource is null or not it is not null.But when i write
this line
con=ds.getConnection();
server gives no response the whole page is white and i not get anything.
Thanks
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you got a non-null value in your "ds" variable, and if you didn't get a class cast exception, the lookup was successful.

Can you verify that the system is "hanging" at the "ds.getConnection()" statement? Are you attempting to use the connection create a SQL statement and execute it? If so, can you verify that the statement is not getting executed?

I'd also look at what you did to define the DataSource on the app server. Verify that it is correct. Also verify that your database server is up and running.


Merrill
Consultant, Sima Solutions
amit sharma
Ranch Hand

Joined: Jul 19, 2006
Posts: 129
Now i reduce the timeout value of connection to 10 sec and now i see the output i get this message
java.sql.SQLException: DBCP could not obtain an idle db connection, pool exhausted.
In my developement environment i also run many context on tomcat 5 and they are working fine.
Thanks
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Increase the "maxActive" value in your DataSource definition. This message indicates that the pool size is too small.

If this doesn't work, show us the xml you used to define the DataSource.
amit sharma
Ranch Hand

Joined: Jul 19, 2006
Posts: 129
I set the connection limit to no limit by setting maxActive to 0 as given in the tomcat site.I also set maxActive to 0 in other context .Is configurations of other context not interfere with this context.
Thanks
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'd suggest changing the maxActive to some number other than zero in both contexts. In a production environment, you don't want an unlimited number of connections. This makes you more vulnerable to a denial of service attack.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Database connection problem
 
Similar Threads
Understand IntialContext
problem in connectivity through datasource to oracle database
WAS 4.05 AEs pooling error
Static method for Obtaining Connection Object in web application
Error:cannot find getDataSource(req)