I m performing a connection pooling operation in jsp.
I created a static function in a particular class called MCE_Server.java and included the following
public static void makeConnectionPool()
{
try
{
cpds = new ComboPooledDataSource();
cpds.setDriverClass("com.mysql.jdbc.Driver");
cpds.setJdbcUrl("jdbc:mysql://localhost:3306/mce_db");
cpds.setUser("root");
cpds.setPassword("xxxxxx");
cpds.setMaxPoolSize(100);
cpds.setMinPoolSize(10);
cpds.setAcquireIncrement(20);
}
catch (PropertyVetoException ex)
{
Logger.getLogger(MCE_Server.class.getName()).log(Level.SEVERE, null, ex);
}
}
Following static function is called from a jsp page
http://................/dbActivatePage.jsp
where i have included the function
<%@page import="xxxxx.MCE_Server"%>
<html>
.
.
.
<body>
<%
MCE_Server.makeConnectionPool();
%>
.
.
.
</body>
</html>
I m planning to get the required Connection as per the static function included in MCE_Server.java as follows:
public static Connection getConnectionfromPool() throws SQLException
{
return cpds.getConnection();
}
i.e whenever i need to get a connection. I’ll include MCE_Server.getConnectionfromPool().
Now the Problem i m having is i m receiving an error
java.sql.SQLException: Connections could not be acquired from the underlying database!
Why I m getting this……??
On Further trial and error method…. i found out that the statements below the code
cpds = new ComboPooledDataSource(); is getting executed.
So, what might be the problem here. Is my approach correct ?
Well looking at the error u r showing.
java.sql.SQLException: Connections could not be acquired from the underlying database!.It seems like your c3p0 configuration is right although i agree with Waldman’s idea of using ServletContextListener. In your case, I strongly believe that the problem has to do something with mysql class path. Please Check whether u have properly included the mysql connector.