Published 30 Oct, 2022

Java - Wildfly datasource does not connect to MySql database

Category Java
Modified : Nov 27, 2022
71

I am completely new to Wildfly/JBoss so i am clueless what to do, i am sitting on this problem since yesterday noon. I am trying to use the mysql-connector-java-8.0.20.jar as the connector and my Wildfly version is wildfly-19.0.0.Final. So the deployment on the server seemed to work fine, but whenever i try to add the datasource and test the connection i am getting this error:

"WFLYJCA0040: failed to invoke operation: WFLYJCA0047: Connection is not valid"

log/ Server throws:

2020-06-19 12:47:04,231 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) WFLYJCA0001: Bound data source [java:jboss/datasources/MySqlDS]
2020-06-19 12:47:04,353 WARN  [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (External Management Request Threads -- 1) IJ000604: Throwable while attempting to get a new connection: null: javax.resource.ResourceException: IJ031084: Unable to create connection
    at [email protected]//org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:345)
    at [email protected]//org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:352)
    at [email protected]//org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:287)
    at [email protected]//org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.createConnectionEventListener(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:1326)
    at [email protected]//org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.getConnection(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:499)
    at [email protected]//org.jboss.jca.core.connectionmanager.pool.AbstractPool.internalTestConnection(AbstractPool.java:1067)
    at [email protected]//org.jboss.jca.core.connectionmanager.pool.strategy.OnePool.testConnection(OnePool.java:93)
    at [email protected]//org.jboss.as.connector.subsystems.common.pool.PoolOperations$TestConnectionInPool.invokeCommandOn(PoolOperations.java:240)
    at [email protected]//org.jboss.as.connector.subsystems.common.pool.PoolOperations$1.execute(PoolOperations.java:97)
    at [email protected]//org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:999)
    at [email protected]//org.jboss.as.controller.AbstractOperationContext.processStages(AbstractOperationContext.java:743)
    at [email protected]//org.jboss.as.controller.AbstractOperationContext.executeOperation(AbstractOperationContext.java:467)
    at [email protected]//org.jboss.as.controller.OperationContextImpl.executeOperation(OperationContextImpl.java:1413)
    at [email protected]//org.jboss.as.controller.ModelControllerImpl.internalExecute(ModelControllerImpl.java:429)
    at [email protected]//org.jboss.as.controller.ModelControllerImpl.lambda$execute$1(ModelControllerImpl.java:246)
    at [email protected]//org.wildfly.security.auth.server.SecurityIdentity.runAs(SecurityIdentity.java:289)
    at [email protected]//org.wildfly.security.auth.server.SecurityIdentity.runAs(SecurityIdentity.java:255)
    at [email protected]//org.jboss.as.controller.ModelControllerImpl.execute(ModelControllerImpl.java:246)
    at [email protected]//org.jboss.as.domain.http.server.DomainApiHandler.handleRequest(DomainApiHandler.java:212)
    at [email protected]//io.undertow.server.handlers.encoding.EncodingHandler.handleRequest(EncodingHandler.java:72)
    at [email protected]//org.jboss.as.domain.http.server.DomainApiCheckHandler.handleRequest(DomainApiCheckHandler.java:93)
    at [email protected]//org.jboss.as.domain.http.server.security.ElytronIdentityHandler.lambda$handleRequest$0(ElytronIdentityHandler.java:62)
    at [email protected]//org.wildfly.security.auth.server.SecurityIdentity.runAs(SecurityIdentity.java:313)
    at [email protected]//org.wildfly.security.auth.server.SecurityIdentity.runAs(SecurityIdentity.java:270)
    at [email protected]//org.jboss.as.controller.AccessAuditContext.doAs(AccessAuditContext.java:254)
    at [email protected]//org.jboss.as.controller.AccessAuditContext.doAs(AccessAuditContext.java:225)
    at [email protected]//org.jboss.as.domain.http.server.security.ElytronIdentityHandler.handleRequest(ElytronIdentityHandler.java:61)
    at [email protected]//io.undertow.server.handlers.BlockingHandler.handleRequest(BlockingHandler.java:56)
    at [email protected]//io.undertow.server.Connectors.executeRootHandler(Connectors.java:376)
    at [email protected]//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
    at [email protected]//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at [email protected]//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
    at [email protected]//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
    at [email protected]//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
    at java.base/java.lang.Thread.run(Thread.java:835)
    at [email protected]//org.jboss.threads.JBossThread.run(JBossThread.java:485)
Caused by: java.sql.SQLException: The server time zone value 'Mitteleurop?ische Sommerzeit' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specifc time zone value if you want to utilize time zone support.
    at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
    at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
    at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
    at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
    at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
    at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76)
    at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
    at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
    at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
    at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
    at [email protected]//org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:321)
    ... 35 more
Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'Mitteleurop?ische Sommerzeit' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specifc time zone value if you want to utilize time zone support.
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
    at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
    at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)
    at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132)
    at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2120)
    at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2143)
    at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1310)
    at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:967)
    at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826)
    ... 39 more

2020-06-19 12:47:04,356 ERROR [org.jboss.as.controller.management-operation] (External Management Request Threads -- 1) WFLYCTL0013: Operation ("test-connection-in-pool") failed - address: ([
    ("subsystem" => "datasources"),
    ("data-source" => "MySqlDS")
]) - failure description: "WFLYJCA0040: failed to invoke operation: WFLYJCA0047: Connection is not valid"

As i said, i an new, so please dont expect to much existing knowledge about wildfly. Thanks in regards!

Answers

There are 2 suggested solutions here and each one has been listed below with a detailed description. The following topics have been covered briefly such as Mysql, Java, Jboss, Wildfly, Connector J. These have been categorized in sections for a clear and precise explanation.

40

Solution 1: Pass the timeZone using the database url on the connector

Your database url should look like jdbc:mysql://ip_address:port/port?serverTimezone=UTC
You can change to your timezone of choice

Solution 2: Change your MySQL configuration file

On ubuntu the configuration file is my.cnf. For ubuntu 18.04 the file's location is /etc/mysql/my.cnf
Add a line as below:
default-time-zone = '+01:00'
Set to your preferred time zone
Restart your MySQL server.


5

Yes thanks, solution 2 worked!
In my case the my.cnf-File was called "my", so that was kinda confusing. I dont know, why it is called like that.
I found the file at this path: C:\ProgramData\MySQL\MySQL Server 8.0