java - A ResourcePool could not acquire a resource from its primary factory or source -


i'm trying connect database in java, using jdbctemplate , i'm gettin error below. have googled long time , solutions found didn't solve problem. tried several different dbs (both sqlserver , mysql) , none worked.

severe: servlet.service() servlet [faces servlet] in context path [/promotion-handler-admin] threw exception [could not open jdbc connection transaction; nested exception java.sql.sqlexception: connections not acquired underlying database!] root cause com.mchange.v2.resourcepool.cannotacquireresourceexception: resourcepool not acquire resource primary factory or source.     @ com.mchange.v2.resourcepool.basicresourcepool.awaitavailable(basicresourcepool.java:1319)     @ com.mchange.v2.resourcepool.basicresourcepool.prelimcheckoutresource(basicresourcepool.java:557)     @ com.mchange.v2.resourcepool.basicresourcepool.checkoutresource(basicresourcepool.java:477)     @ com.mchange.v2.c3p0.impl.c3p0pooledconnectionpool.checkoutpooledconnection(c3p0pooledconnectionpool.java:525)     @ com.mchange.v2.c3p0.impl.abstractpoolbackeddatasource.getconnection(abstractpoolbackeddatasource.java:128)     @ org.springframework.jdbc.datasource.datasourcetransactionmanager.dobegin(datasourcetransactionmanager.java:202)     @ org.springframework.transaction.support.abstractplatformtransactionmanager.gettransaction(abstractplatformtransactionmanager.java:371)     @ org.springframework.transaction.interceptor.transactionaspectsupport.createtransactionifnecessary(transactionaspectsupport.java:335)     @ org.springframework.transaction.interceptor.transactioninterceptor.invoke(transactioninterceptor.java:105)     @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172)     @ org.springframework.aop.framework.cglib2aopproxy$dynamicadvisedinterceptor.intercept(cglib2aopproxy.java:622)     ... 

this properties file:

app.driverclassname=net.sourceforge.jtds.jdbc.driver app.url=jdbc:sqlserver://myurl:port;databasename=my_database app.username=myusername app.password=mypassword 

webapp/web-inf/applicationcontext-database.xml:

<beans:bean id="datasource" class="com.mchange.v2.c3p0.combopooleddatasource"     destroy-method="close">     <beans:property name="driverclass" value="${app.driverclassname}" />     <beans:property name="jdbcurl"         value="${app.url}" />     <beans:property name="user" value="${app.username}" />     <beans:property name="password" value="${app.password}" />     <beans:property name="acquireincrement" value="5" />     <beans:property name="idleconnectiontestperiod" value="600" />     <beans:property name="maxpoolsize" value="10" />     <beans:property name="maxstatements" value="5" />     <beans:property name="minpoolsize" value="3" />     <beans:property name="preferredtestquery" value="select 1 dual" /> </beans:bean>  <!-- transaction_managers --> <!-- see http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html -->  <!-- default --> <beans:bean id="transactionmanager"     class="org.springframework.jdbc.datasource.datasourcetransactionmanager">     <beans:property name="datasource" ref="datasource" /> </beans:bean> 

dao class:

@repository public class campaigndao {     private jdbctemplate jdbctemplate;      @resource(name = "datasource")     public void setdatasource(datasource datasource) {         this.jdbctemplate = new jdbctemplate(datasource);     }  public list<campaign> getcampaignlist() {     long start = system.currenttimemillis();      list<campaign> querylist;      try {         querylist = jdbctemplate.query("select * campaign", new rowmapper<campaign>() {             public campaign maprow(resultset rs, int line) throws sqlexception {                 campaign campaign = new campaign();                 campaign.setid(rs.getlong("id"));                 campaign.setextrainfo(rs.getstring("extra_info"));                 campaign.setbegintime(rs.getdate("begin_time"));                 campaign.setendtime(rs.getdate("end_time"));                  return campaign;              }         });     } {          ...     }     return querylist; } 

for finds question in future. doing wrong was using jtds driver , forgot add in url. in properties file should have done was:

app.url=jdbc:jtds:sqlserver://myurl:port;databasename=my_database 

Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -