vert-x3 / vertx-mysql-postgresql-client

This client is deprecated - use instead
https://github.com/eclipse-vertx/vertx-sql-client
Apache License 2.0
117 stars 59 forks source link

Could not initialize class com.github.mauricio.async.db.mysql.MySQLConnection$ #161

Closed worldflyingct closed 5 years ago

worldflyingct commented 5 years ago

my gradle file is :

dependencies {
    compile "io.vertx:vertx-core:3.7.1"
    compile "io.vertx:vertx-jdbc-client:3.7.1"
    compile "io.vertx:vertx-mysql-postgresql-client:3.7.1"
}

my java file is:

public static void Init (Vertx vertx) {
    client = MySQLClient.createShared(vertx, new JsonObject()
                .put("host", "localhost")
                .put("database", "homepage")
                .put("username", "root")
                .put("password", "root"));
    }
}

my run function is:

client.getConnection(res -> {
    if (res.succeeded()) {
        SQLConnection connection = res.result();
        connection.query(sql, res2 -> {
            if (res2.succeeded()) {
                ResultSet rs = res2.result();
                System.out.println("Run sql success");
                List<JsonObject> rows = rs.getRows();
                for(int i = 0 ; i < rows.size() ; i++) {
                    System.out.println(rows.get(i));
                }
            } else {
                System.out.println("Run sql fail");
            }
        });
    } else {
        System.out.println("Failed to get connection");
    }
});

when I querysql, a issue happened. log as follow:

六月 20, 2019 1:39:52 上午 io.vertx.ext.asyncsql.impl.pool.AsyncConnectionPool
信息: creating a connection went wrong
java.lang.NoClassDefFoundError: Could not initialize class com.github.mauricio.async.db.mysql.MySQLConnection$
        at com.github.mauricio.async.db.mysql.MySQLConnection.<init>(MySQLConnection.scala:58)
        at io.vertx.ext.asyncsql.impl.pool.MysqlAsyncConnectionPool.create(MysqlAsyncConnectionPool.java:42)
        at io.vertx.ext.asyncsql.impl.pool.AsyncConnectionPool.createAndConnect(AsyncConnectionPool.java:94)
        at io.vertx.ext.asyncsql.impl.pool.AsyncConnectionPool.access$500(AsyncConnectionPool.java:39)
        at io.vertx.ext.asyncsql.impl.pool.AsyncConnectionPool$1.lambda$handle$0(AsyncConnectionPool.java:81)
        at io.vertx.core.impl.VertxImpl$InternalTimerHandler.handle(VertxImpl.java:911)
        at io.vertx.core.impl.VertxImpl$InternalTimerHandler.handle(VertxImpl.java:875)
        at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:320)
        at io.vertx.core.impl.EventLoopContext.execute(EventLoopContext.java:43)
        at io.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:188)
        at io.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:180)
        at io.vertx.core.impl.VertxImpl$InternalTimerHandler.run(VertxImpl.java:901)
        at io.netty.util.concurrent.PromiseTask$RunnableAdapter.call(PromiseTask.java:38)
        at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:127)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:495)
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:905)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.lang.Thread.run(Unknown Source)
oshai commented 5 years ago

Try the jasync version. It is replacing the old one.