0

I am trying to connect to mysql. Below are the jars i am using for this purpose,

1. c3p0-0.9.5.5.jar
2. hibernate-c3p0-5.4.19.Final.jar
3. hibernate-core-5.4.19.Final.jar
4. mysql-connector-java-5.1.44.jar ( have tried with 8.x above version as well)

Below is my .xml content

<session-factory>

    <!-- JDBC Database connection settings -->
    <property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://localhost:3306/devenv?useSSL=false&amp;serverTimezone=UTC</property>
    <property name="connection.username">newuser</property>
    <property name="connection.password">newuser12#</property>

    <!-- JDBC connection pool settings ... using built-in test pool -->
    <property name="connection.pool_size">1</property>

    <!-- Select our SQL dialect -->
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

    <!-- Echo the SQL to stdout -->
    <property name="show_sql">true</property>

    <!-- Set the current session context -->
    <property name="current_session_context_class">thread</property>

</session-factory>

Below is my error message :

[C3P0PooledConnectionPoolManager[identityToken->1hgery9ab1a070yr7e982f|51d673db]-HelperThread-#0] 
WARN com.mchange.v2.resourcepool.BasicResourcePool - com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@2df67b58 
-- Acquisition Attempt Failed!!! Clearing pending acquires. 
While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). 
Last acquisition attempt exception: 
java.sql.SQLException: Unknown system variable 'query_cache_size'
    at 
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:545)

Solution which have tried :

  1. Tried with sql connector 8.x above and 5.x
  2. Tried with different sql user
  3. Tried adding query_cache_type and query_cache_size as a variable in my.ini file. No variable have been created in db after adding entry in my.ini

More info.

I was able to connect to db earlier using sql connector 8.x when I tested jdbc connection. Now i have created a mvc project, while trying now, facing this error.

Need netizens help on this !

Som
  • 1,522
  • 1
  • 15
  • 48
Durairaj s
  • 193
  • 3
  • 13
  • 1
    Looks like same error https://stackoverflow.com/questions/49984267/java-sql-sqlexception-unknown-system-variable-query-cache-size – J Asgarov Jul 31 '20 at 17:30
  • Yeah tried that as well. Still facing same. Am I missing anything else .. – Durairaj s Jul 31 '20 at 17:31
  • 1
    you can try following Baeldung guide for c3p0: https://www.baeldung.com/hibernate-c3p0, their pom file is here (just add c3p0 dependency) https://github.com/eugenp/tutorials/tree/master/persistence-modules/hibernate5 – J Asgarov Jul 31 '20 at 17:44
  • btw, because you said jars, are you using maven? some of your problems could go away if you let maven or gradle get the dependencies for you – J Asgarov Jul 31 '20 at 17:48
  • 1
    fundamentals is nice and all but then you need to check which transitive dependencies your jars need and make sure these are on the classpath for it to work. Just my 2 cents, I don't think knowing how to work without maven/gradle is a valuable skill. But if you insist I would still create a second project with maven where it works and run `mvn dependency:tree` to find all the transitive dependencies you need to bring in. – J Asgarov Jul 31 '20 at 18:17
  • 1
    I'd try running `mvn dependency:tree` with your working solution vs the non working solution and look for differences in database related dependencies. – Robert Bain Jul 31 '20 at 23:50

0 Answers0