0

I'm trying to use vertx JDBC with MS SQL Server.

I get the following stacktrace:

Exception in thread "vertx-jdbc-service-get-connection-thread" Exception in thread "vertx-jdbc-service-get-connection-thread" java.lang.NoSuchMethodError: 'java.sql.Connection io.agroal.api.transaction.TransactionIntegration.getConnection()'
    at io.agroal.pool.ConnectionPool.wrapperFromTransaction(ConnectionPool.java:162)
    at io.agroal.pool.ConnectionPool.getConnection(ConnectionPool.java:129)
    at io.agroal.pool.DataSource.getConnection(DataSource.java:61)
    at io.vertx.ext.jdbc.impl.JDBCClientImpl.lambda$null$4(JDBCClientImpl.java:232)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    at java.base/java.lang.Thread.run(Thread.java:831)
java.lang.NoSuchMethodError: 'java.sql.Connection io.agroal.api.transaction.TransactionIntegration.getConnection()'
    at io.agroal.pool.ConnectionPool.wrapperFromTransaction(ConnectionPool.java:162)
    at io.agroal.pool.ConnectionPool.getConnection(ConnectionPool.java:129)
    at io.agroal.pool.DataSource.getConnection(DataSource.java:61)
    at io.vertx.ext.jdbc.impl.JDBCClientImpl.lambda$null$4(JDBCClientImpl.java:232)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    at java.base/java.lang.Thread.run(Thread.java:831)

part of my build.gradle:

  implementation platform("io.vertx:vertx-stack-depchain:4.2.1")
  implementation "io.vertx:vertx-core"
  implementation 'io.vertx:vertx-jdbc-client:4.2.1'
  implementation "io.vertx:vertx-lang-groovy"
  implementation 'io.agroal:agroal-api:1.13'
  implementation 'io.agroal:agroal-pool:1.13'
  implementation "com.microsoft.sqlserver:mssql-jdbc:9.4.0.jre16"

I tried choosing other versions, but I always get the same error. I tried looking for the library function, but I can't find any version of TransactionIntegration with a getConnection() method.

My code:

import io.vertx.core.AbstractVerticle;
import io.vertx.core.*;
import io.vertx.jdbcclient.JDBCConnectOptions;
import io.vertx.jdbcclient.JDBCPool;
import io.vertx.sqlclient.*;

public class MainVerticle extends AbstractVerticle {

     @Override
     public void start(Promise<Void> startPromise) throws Exception {

        JDBCPool pool = JDBCPool.pool(
                vertx,
                new JDBCConnectOptions()
                .setJdbcUrl("jdbc:sqlserver://some_ip;databaseName=mydatabase")
                .setUser("user")
                .setPassword("password"),
                new PoolOptions().setMaxSize(16)
                );
        pool
          .query("SELECT * FROM test")
          .execute()
          .onFailure(e -> {
              e.printStackTrace();
          })
    }
}
waldelb
  • 705
  • 6
  • 11

2 Answers2

0

The current 4.2.1 release seems to rely on agroal 1.12.

Given that you're getting a NoSuchMethodError I would assume it can be related to the fact that the compiled jar was against 1.12, but you're running against an older version, maybe 1.0 or 1.1. Looking at github you can find that trace to match those versions.

Try to upgrade to 1.12, and it should solve your error.

Paulo Lopes
  • 5,845
  • 22
  • 31
  • Unfortunately, no. The error doesn't change. And I can't find any version, that has this method: https://github.com/agroal/agroal/commits/master/agroal-api/src/main/java/io/agroal/api/transaction/TransactionIntegration.java – waldelb Nov 17 '21 at 11:05
  • The issue is that somewhere in your project one dependency is pulling agroal 1.1 or 1.0 as that matches perfectly the stacktrace you listed: https://github.com/agroal/agroal/blob/1.0/agroal-pool/src/main/java/io/agroal/pool/ConnectionPool.java#L162 Look at line 162. Given that vertx jdbc is built against 1.12 this causes problems. – Paulo Lopes Nov 18 '21 at 12:18
  • Hm. Any idea how I could detect where this happens? – waldelb Nov 18 '21 at 12:31
  • The problem can apparently be solved by removing the agroal dependencies, refreshing gradle, inserting the exact same agroal dependencies, and refreshing again. – waldelb Nov 19 '21 at 09:31
0

Apparently, gradle is just bugged.

I changed agroal version to 1.12, as suggested by Paulo Lopes. However, this did not solve the problem.

I don't know, what exactly solved it, but I'll just list exactly what I did:

  • removing both agroal dependencies
  • inserting agroal-api
  • removing agroal-api
  • inserting agroal-api
  • inserting agroal-pool

I did not check, whether or not it was necessary to use agroal 1.12, or what step exactly solved it. And I don't intend to try it, I'm just happy, it finally works.

waldelb
  • 705
  • 6
  • 11