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

前端 未结 5 1375
清歌不尽
清歌不尽 2020-12-16 17:17

I\'m trying to connect to a database in Java, using jdbcTemplate and I\'m gettin the error below. I have Googled for a long time and all solutions I found didn\'t solve my p

相关标签:
5条回答
  • 2020-12-16 17:42

    I got this problem on c3p0 0.9.5-pre6 with mchange-commons-java 0.2.6.3. After downgrading to c3p0 0.9.5-pre5 and mchange-commons-java 0.2.6.2, the problem disappears.

    0 讨论(0)
  • 2020-12-16 17:45

    In my case the problem was related with version mismach between MySQL and mysql-connector-java. After few days of headache I took out my ComboPooledDataSource module in a separate clean project and tried to connect with it to MySQL. However, I got stacktrace (unfortunatly I forgot what exactly were there), with which I understood that the problem is related with versions.

    0 讨论(0)
  • 2020-12-16 17:48

    This message can also be displayed, if, like me, you run your application with the Maven plugin for Tomcat:

    mvn clean install tomcat7:run
    

    and you have a provided scope element in your Maven dependency:

    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.36</version>
      <scope>provided</scope>
    </dependency>
    

    The provided scope will prevent the connector from being part of the war archive and the Tomcat plugin will find no connector to establish the database connection.

    Simply removing the provided scope from the dependency solves the issue.

    0 讨论(0)
  • 2020-12-16 17:55

    For anyone that finds this question in the future. What I was doing wrong was that I was using the jtds driver and I forgot to add that in the url. So in my properties file what I should have done was:

    app.url=jdbc:jtds:sqlserver://myUrl:port;databaseName=my_database
    
    0 讨论(0)
  • 2020-12-16 18:04

    For anyone that finds this question in the future.

    This can also be caused by a missing database driver.

    In my case I was using the maven-shade-plugin with the minimizeJar option set. This - of course - was throwing away the jtds driver because it is not directly referenced anywhere.

    This can be fixed as follows:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>1.6</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <minimizeJar>true</minimizeJar>
              <filters>
                <filter>
                  <!-- Make sure jtds is included. -->
                   <artifact>net.sourceforge.jtds:jtds</artifact>
                   <includes>
                       <include>**</include>
                   </includes>
                </filter>
                <filter>
                  <artifact>*:*</artifact>
                  <excludes>
                    <exclude>META-INF/*.SF</exclude>
                    <exclude>META-INF/*.DSA</exclude>
                    <exclude>META-INF/*.RSA</exclude>
                    <exclude>META-INF/*.sf</exclude>
                    <exclude>META-INF/*.dsa</exclude>
                    <exclude>META-INF/*.rsa</exclude>
                  </excludes>
                </filter>
              </filters>
            </configuration>
          </execution>
        </executions>
      </plugin>
    
    0 讨论(0)
提交回复
热议问题