my dog learned polymorphism*
The moose likes Tomcat and the fly likes Connection Pooling Managment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Connection Pooling Managment" Watch "Connection Pooling Managment" New topic
Author

Connection Pooling Managment

Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
Hi all,

I am configuring datasource for my tomcat v.5.5.25. i did following entry in my context.xml


<Resource name="jdbc/mydatasource" auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
url="jdbcracle:thin:@url:servicename"
username="user" password="password"/>


---------------------------------------------------------------------------
public static Connection getConnection() {
Connection conn = null;
if (datasource == null) {
datasource = locateDataSource();

}
if (datasource != null) {
try {
conn = datasource.getConnection();
} catch (SQLException e) {
LOGGER.error("Cannot get connection:" + e.getMessage()+e);
}
}

return conn;
}
/**
* Method to locate data source.
* @return
*/
private static DataSource locateDataSource() {
Context initialContext = null;
String DATASOURCE_CONTEXT = "java:comp/env/jdbc/mydatasource";
try {
initialContext = new InitialContext();
datasource = (DataSource)initialContext.lookup(DATASOURCE_CONTEXT);

} catch (NamingException e) {
LOGGER.error("Cannot get connection:" + e.getMessage() +e);
}
return datasource;

}
-----------------------------------------------------------------------
i take connection like this for my data access layer
connection = DBUtil.getConnection();


there is no problem in picking connections. But as per my reading it is not doing connection pooling at all. Application gets too slow and hangs too often that i have to restart it.
and also how can i make it to use c3p0 for connection pooling.
i have following jar in my tomcat/common/lib - commons-dbcp-1.2.1.jar,ojdbc14.jar

Please suggest.

Thanks in advance
Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
Would any one like to reply on this post???

Please help
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

How do you know that it's not pooling connections?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
I need to do following changes in the current scenario

1. To make it to use C3P0
2. it is taking so much time in executing a query. Can connection pooling like this help me in accelerating the speed at which queries fire.

I will be really thankful if anyone can help me in solving my problem.

Thanks in advance
Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
is there nobody who can help me in resolving this problem?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Patricia Samuel:
is there nobody who can help me in resolving this problem?


I think you'll more and better responses if you can make your questions a little more clear.

1.) What is C3PO (other than the little robot in Star Wars)?

2.) Establishing a connection to a database is often a very expensive process and can often be the biggest bottleneck in an application. Keeping a pool of already established connections will almost always be faster than creating them on demand.


Beyond those things, do you have another question?
[ May 30, 2008: Message edited by: Ben Souther ]
Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
Originally posted by Ben Souther:

Keeping a pool of already established connections will almost always be faster than creating them on demand.
[ May 30, 2008: Message edited by: Ben Souther ]


Hi Ben,

Many thanks for your reply. Would you please explain me how can we make faster our application by having a pool of already established connection. I am more concern about the performance of my application.I would appreciate if some one can help me know the way to make application faster.

Thanks a lot
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Are you using connection pooling now?
Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
Yes, i am still using the code that i mentioned in my first post regarding this.i have set maxsize and minsize. But my application does not execute query fast.My tomcat is using dpcp for connection pooling.
 
Don't get me started about those stupid light bulbs.
 
subject: Connection Pooling Managment
 
Similar Threads
javax.naming.NamingException: Cannot create resource instance
Solution ------ Cannot create JDBC driver of class '' for connect URL 'null'
Using datasource for login bean & login page?
How to specify the name of the database
Create ConnectionPool in ServletContextListener