crate / crate-jdbc

A JDBC driver for CrateDB.

Home Page:https://crate.io/docs/jdbc/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SQLFeatureNotSupportedException - while using with Vert.x JDBC

rajanikanthy opened this issue · comments

While using Crate JDBC with Vert.x and trying to insert a set of records on a prepared statement throws this exception. Please see the code below.

import io.reactivex.Observable
import io.vertx.core.AbstractVerticle
import io.vertx.core.Future
import io.vertx.core.json.JsonArray
import io.vertx.core.json.JsonObject
import io.vertx.core.logging.Logger
import io.vertx.core.logging.LoggerFactory
import io.vertx.ext.jdbc.JDBCClient
import io.vertx.ext.sql.SQLConnection

class CrateJdbcVerticle : AbstractVerticle() {

    val _logger: Logger = LoggerFactory.getLogger(CrateJdbcVerticle::class.java)

    var jdbcClient: JDBCClient? = null

    val sqlDropTable = "DROP TABLE IF EXISTS TEST_DATA"
    val sqlCreateTable = "CREATE TABLE TEST_DATA(id integer primary key, first_name string, last_name string)";
    val insertQuery = "INSERT INTO TEST_DATA(id, first_name, last_name) VALUES (?, ?, ?)";

    val batch = mutableListOf(
            JsonArray().add(1).add("Cathrine").add("Barretta"),
            JsonArray().add(2).add("Ambrose").add("Trahan"),
            JsonArray().add(3).add("Christine").add("Anaya"),
            JsonArray().add(4).add("Hubert").add("Lebow"),
            JsonArray().add(5).add("Cora").add("Messersmith"),
            JsonArray().add(6).add("Candra").add("Rain"),
            JsonArray().add(7).add("Anastacia").add("Sala"),
            JsonArray().add(8).add("Lester").add("Chattin"),
            JsonArray().add(9).add("Treva").add("Glazier"),
            JsonArray().add(10).add("Joline").add("Shilling"),
            JsonArray().add(11).add("Lena").add("Cheers"),
            JsonArray().add(12).add("Alec").add("Rew"),
            JsonArray().add(13).add("Roseline").add("Fredrick"),
            JsonArray().add(14).add("Davis").add("Fludd"),
            JsonArray().add(15).add("Celia").add("Whitsett"),
            JsonArray().add(16).add("Vera").add("Gathings"),
            JsonArray().add(17).add("Ana").add("Kemplin"),
            JsonArray().add(18).add("Scott").add("Sisneros"),
            JsonArray().add(19).add("Bridgette").add("Wooding"),
            JsonArray().add(20).add("Herlinda").add("Madson")
    );

    override fun start(startFuture: Future<Void>?) {
        val config = JsonObject().put("url", "crate://localhost:5433/").put("driver_class", "io.crate.client.jdbc.CrateDriver").put("max_pool_size", 30)
        jdbcClient = JDBCClient.createShared(vertx, config)
        initializeData()
        startFuture?.complete()
    }

    override fun stop(stopFuture: Future<Void>?) {
        stopFuture?.complete();
    }

    private fun initializeData() {
        getConnection().subscribe(
                {
                    connection ->
                    connection.execute(sqlDropTable, {
                        dropTableHandler ->
                        if (dropTableHandler.succeeded()) {
                            connection.execute(sqlCreateTable, {
                                createTableHandler ->
                                if (createTableHandler.succeeded()) {
                                    batch.forEach({
                                        item ->
                                        connection.updateWithParams(insertQuery, item, {
                                            result ->
                                            if (result.succeeded()) {
                                                _logger.info("insert completed successfully");
                                            } else {
                                                _logger.error(result.cause())
                                            }
                                        });
                                    })
                                } else {
                                    _logger.error(createTableHandler.cause());
                                }
                            })
                        } else {
                            _logger.error(dropTableHandler.cause());
                        }
                    })
                }
        )
    }

    private fun getConnection(): Observable<SQLConnection> {
        return Observable.create {
            emitter ->
            jdbcClient?.getConnection({
                result ->
                if (result.succeeded()) {
                    emitter.onNext(result.result())
                    emitter.onComplete()
                } else {
                    emitter.onError(result.cause())
                }

            })
        }
    }
}`

Output:

Jun 02, 2017 2:46:57 PM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource 
INFO: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 1hge1379otmjvtq8msp23|775bd756, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> io.crate.client.jdbc.CrateDriver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 1hge1379otmjvtq8msp23|775bd756, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> crate://localhost:5433/, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 30, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported
Jun 02, 2017 2:46:58 PM com.og.vertx.CrateJdbcVerticle
SEVERE: java.sql.SQLFeatureNotSupportedException: Connection: prepareStatement(String sql, int autoGeneratedKeys) not supported

hi @rajanikanthy, yes we are aware of that. we don't fully support prepared statements, see our documentation. although this is already on our backlog it is not very likely that this is in crate / crate-jdbc any time soon. https://crate.io/docs/reference/jdbc/#compatibility

if this is just a batch insertion use case you could use unnest (http://crate.readthedocs.io/projects/crate/en/1.1.0/sql/table_functions.html#unnest-array-array) with insert.

here is an example in java:

            Statement stmt = conn.createStatement();
            stmt.executeUpdate("create table t (x string, b boolean) with (number_of_replicas = 0)");
            PreparedStatement preparedStatement = conn.prepareStatement(
                "insert into t (x, b) select * from unnest(?, ?)");
            preparedStatement.setArray(1, conn.createArrayOf("string", new Object[]{"a", "b"}));
            preparedStatement.setArray(2, conn.createArrayOf("boolean", new Object[]{true, false}));
            preparedStatement.execute();

or use executeBatch as describe under https://github.com/crate/crate-sample-apps/blob/master/java/documentation.md#executing-multiple-statements-bulk-operations

hi @rajanikanthy, did this help you? does it work for you like that?

hi @rajanikanthy, as i didn't hear back from you i'm closing this issue now. if there's still a problem you can reopen it anytime.

@rajanikanthy Did you get crate working with Vert.x? I am facing the same problem The class that I am using is io.vertx.reactivex.ext.jdbc.JDBCClient for the JDBC Connectivity and I use rxUpdate method for the insert

JDBCClient client = JDBCClient.createShared(this.vertx, this.config);
client.rxUpdate("INSERT INTO test(name) VALUES ('Test'));