0

I have attempted working with SQLite and h2 databases, with the sqlite-jdbc-3.20.1.jar /h2-1.4.195.jar in the classpath.

I have the h2 driver jar in my pom.xml, didn't seem to make a difference at runtime.

<dependency>
   <groupId>com.h2database</groupId>
   <artifactId>h2</artifactId>
   <version>1.4.195</version>
</dependency>

I copied the jars to target directory in the hopes that "java -cp target/*" might get these jars right into the class path. All to no avail. I am getting this error that's driving me crazy, it won't tell me what class it didn't find

    Causing: java.sql.SQLException: Unable to load class:  

from ClassLoader:sun.misc.Launcher$AppClassLoader@18b4aac2;ClassLoader:sun.misc.Launcher$AppClassLoader@18b4aac2

` ... 24 more
... org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator: HHH000342: Could not obtain connection to query metadata

Caused by: java.lang.ClassNotFoundException:   
            at java.lang.Class.forName0(Native Method)  
            at java.lang.Class.forName(Class.java:348)  
        at > >org.tomcat.jdbc.pool.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:38)

I have printed the maven tree and used verbose:class option and do find driver class loaded. I have dropwizard-hibernate package in my maven dependencies. OK, any way to coerce this thing to tell me which class it is not able to find?!

Addendum:

My Config.yml


logging:
  level: INFO
  loggers:
    com.srini.testdw: DEBUG
database:
  driverClass: org.h2.Driver
  user: "sa"
  password: ""
  url: jdbc:h2:./testdb
  properties:
    charSet: UTF-8
    maxWaitForConnection: 1s
    validationQuery: "/* MyService Health Check */ SELECT 1"
    minSize: 8
    maxSize: 32
    checkConnectionWhileIdle: false
    evictionInterval: 10s
    minIdleTime: 1 minute
    hibernate.dialect: org.hibernate.dialect.H2Dialect
    hibernate.show_sql: true
    hibernate.generate_statistics: false
    hibernate.hbm2ddl.auto: validate

server:
  minThreads: 2
  maxQueuedRequests: 3
  type: simple
SriniMurthy
  • 113
  • 2
  • 13
  • Could you post the configuration of your tomcat connection pool? The root cause is most likely that the pool is not able to load the configured JDBC driver. https://apache.googlesource.com/tomcat/+/d000040c312f0b303293ad7ac8a67e88ff1850cb/java/org/apache/tomcat/jdbc/pool/PooledConnection.java#133 – Andreas Feb 26 '18 at 20:56
  • @Andreas, I am using the built in jetty server, not sure at all. There is nothing specific in the config.yml I have used for pool configuration. – SriniMurthy Feb 27 '18 at 06:04
  • in your config is a section `database:` this section has a property `driverClass : org.postgresql.Driver`. The value you have set there is most likely wrong. You are using the Tomcat JDBC Connection Pool, there is no relation between the servlet container (Jetty, Tomcat, Undertow) and your database connection pool (Tomcat, Hikari, C3PO) despite being programmed by the Tomcat team and often used with a Tomcat servlet container. – Andreas Feb 27 '18 at 10:53
  • database: driverClass: org.h2.Driver user: "sa" password: "" url: jdbc:h2:./testdb properties: charSet: UTF-8 maxWaitForConnection: 1s validationQuery: "/* MyService Health Check */ SELECT 1" minSize: 8 maxSize: 32 checkConnectionWhileIdle: false evictionInterval: 10s minIdleTime: 1 minute hibernate.dialect: org.hibernate.dialect.H2Dialect hibernate.show_sql: true hibernate.generate_statistics: false – SriniMurthy Feb 27 '18 at 17:41
  • Sorry, couldn't seem to be able to format the config.yml I posted above – SriniMurthy Feb 27 '18 at 17:42
  • Looks like I resolved the problem accidentally, without having to change anything much. The server configuration in my config.yml reads "simple", looks like getting rid of that resolved my issue. Thank you @Andreas for your inputs – SriniMurthy Feb 28 '18 at 17:45

0 Answers0