spring-boothibernatehostingtomcat8

java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/nextste2_next_step


I am trying to host my Spring Boot Application with hibernate to Tomcat 8 server that I purchased on Dailyrazor, however, I am encountering some issues. Every time I attempt to access my domain the page fails with a 404 error message. When I check my Tomcat log file I get the following message:

org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 19
    at org.apache.tomcat.util.bcel.classfile.Constant.readConstant(Constant.java:127)
    at org.apache.tomcat.util.bcel.classfile.ConstantPool.<init>(ConstantPool.java:59)
    at org.apache.tomcat.util.bcel.classfile.ClassParser.readConstantPool(ClassParser.java:168)
    at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:92)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:1990)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1940)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1915)
    at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1876)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1145)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:767)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:302)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5074)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:919)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1704)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
ERROR next-step-co.com-startStop-2 org.apache.catalina.core.StandardContext - Error during ServletContainerInitializer processing
javax.servlet.ServletException: Failed to instantiate WebApplicationInitializer class
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:158)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5164)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:919)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1704)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ExceptionInInitializerError
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:155)
    ... 12 more
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:275)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
    at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
    at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:175)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:118)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:473)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:84)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:689)
    at com.arkan.registration.config.SessionFactoryCreator.createSessionFactory(SessionFactoryCreator.java:56)
    at com.arkan.registration.Run.<clinit>(Run.java:36)
    ... 17 more
Caused by: org.hibernate.exception.JDBCConnectionException: Error calling DriverManager#getConnection
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:112)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
    at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:118)
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionCreator.makeConnection(DriverManagerConnectionCreator.java:37)
    at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:58)
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections.addConnections(DriverManagerConnectionProviderImpl.java:331)
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections.<init>(DriverManagerConnectionProviderImpl.java:250)
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections.<init>(DriverManagerConnectionProviderImpl.java:228)
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections$Builder.build(DriverManagerConnectionProviderImpl.java:369)
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:98)
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:73)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:107)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:246)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
    ... 31 more
Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/nextste2_next_step
    at java.sql.DriverManager.getConnection(DriverManager.java:689)
    at java.sql.DriverManager.getConnection(DriverManager.java:208)
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionCreator.makeConnection(DriverManagerConnectionCreator.java:34)

I am very new to hosting so I am unsure what this error means. Here is my hibernate.cfg file and my application.properties file:

Hibernate.cfg

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" >
<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name="hibernate.connection.drive_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/nextste2_next_step</property>
        <property name="hibernate.connection.username">nextste2_abdullah</property>
        <property name="hibernate.connection.password">Unknowndude1</property>

        <!-- SQL Dialect -->
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL55Dialect</property>
        <property name="hbm2ddl.auto">update</property>
        <property name="show_sql">true</property>
        <property name="hibernate.use_sql_comments">true</property>
        <property name="hibernate.format_sql">true </property>

<!--        <property name="hibernate.cache.use_second_level_cache">true</property>-->
<!--        <property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>-->
<!--        <property name="hibernate.cache.use_query_cache">true</property>-->
    </session-factory>
</hibernate-configuration>

application.properties file:

# Database Details
#spring.datasource.url = jdbc:mysql://localhost/next_step?sessionVariables=sql_mode='NO_ENGINE_SUBSTITUTION'&jdbcCompliantTruncation=false
#spring.datasource.username = abdullah
#spring.datasource.password = app12341234
spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver

spring.datasource.url = jdbc:mysql://localhost:3306/nextste2_next_step?sessionVariables=sql_mode='NO_ENGINE_SUBSTITUTION'&jdbcCompliantTruncation=false
spring.datasource.username = nextste2_abdullah
spring.datasource.password = Unknowndude1
#spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver

# Spring Security login queries
security.basic.enabled = false
spring.queries.users-query=SELECT username, password, '1' FROM auth_user WHERE username = ? and STATUS = 'VERIFIED'
spring.queries.roles-query=SELECT auth_user.username AS username, auth_role.role_name AS role FROM auth_user INNER JOIN auth_user_role ON auth_user.auth_user_id = auth_user_role.userId INNER JOIN auth_role ON auth_user_role.roleId = auth_role.auth_role_id WHERE auth_user.username = ?
spring.queries.users-business-query = SELECT username, password, '1' FROM auth_user_business WHERE username = ? and STATUS = 'VERIFIED'
spring.queries.users-business-role-query = SELECT auth_user_business.username AS username, auth_role.role_name AS role FROM auth_user_business INNER JOIN business_user_role ON auth_user_business.auth_business_id = business_user_role.businessId INNER JOIN auth_role ON business_user_role.roleId = auth_role.auth_role_id WHERE auth_user_business.username = ?;


# Setting the max file upload

spring.servlet.multipart.max-file-size=100000MB
spring.servlet.multipart.max-request-size=100000MB

I have tried looking for solutions on varies websites but to no avail.


Solution

  • If not added this dependency, add this dependency in the pom.xml file

    <dependency>
       <groupId>com.mysql</groupId>
       <artifactId>mysql-connector-j</artifactId>
       <scope>runtime</scope>
    </dependency>
    

    AND change the dialect from

    <property name="hibernate.dialect">org.hibernate.dialect.MySQL55Dialect</property>
    

    to

    <property name="hibernate.dialect">org.hibernate.dialect.MySQL8Dialect</property>
    

    And last also change the driver in hibernate.xml file

    <property name="hibernate.connection.drive_class">com.mysql.jdbc.Driver</property>
    

    to

    <property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
    

    You have made the mistake in the hibernate.xml in hibernate.connection.drive_class properties it should be changed to hibernate.connection.driver_class

    Also if the answer helps you please upvote the solution :)