简体   繁体   中英

I need to get the underlying java.sql.Connection from Vert.x's SQLConnection

I'm using vert.x's JDBCClient to get my database connections and it only gives me io.vertx.ext.sql.SQLConnection or io.vertx.reactivex.ext.sql.SQLConnection and none of them extends java.sql.Connection.

In order to call Liquibase from a verticle I need a java.sql.Connection.

I know that Vert.x uses C3Po on behind but I was not able to find any method that could give me the underlying connection.

How can I achieve that ?

If you're on a recent version, SQLConnection has an unwrap method. As indicated in the docs :

default <N> N unwrap()

Return the underlying Connection object if available. This is not mandated to be implemented by the clients.

The JDBCClient should return a java.sql.Connection . Don't forget to call close on the original SQLConnection after usage.

Have you tried with:

final JDBCClient dbClient = JDBCClient.createShared(vertx, new JsonObject()
            .put("url", dbUrl)
            .put("user", user)
            .put("password", pass)
            .put("driver_class", "you.driver")
            .put("max_pool_size", 30)
    );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM