Baffled by a JDBI JUnit test error

609 views
Skip to first unread message

Mark Griffin

unread,
Jun 10, 2014, 3:56:00 PM6/10/14
to jd...@googlegroups.com
I have the following test that fails. The SQL is legit and, in fact, the same query mapped to a DAO works at runtime just fine. However, when I run this as a unit test it fails. I get the same error regardless if I use my runtime spring config and inject the DBIFactory, or if I simply do the following. I'm totally perplexed!

This is using mysql 5.6.19, JDBI 2.55 and mysql-connector-java 5.1.31

The test code is:

    @Test
    public void testFindByUsername() throws Exception {
        DBI dbi = new DBI("jdbc:mysql://localhost:3306/testdb", "testuser", "testpass");
        Handle h = dbi.open();
        String name = h.createQuery("select username from users where userId = :id")
                .bind("id", 1)
                .map(StringMapper.FIRST)
                .first();

        Assert.isTrue("someuser".equals(name));
        h.close();
    }


The stacktrace is:

org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException: Could not clean up [statement:"select username from users where userId = :id", located:"select username from users where userId = :id", rewritten:"select username from users where userId = ?", arguments:{ positional:{}, named:{id:1}, finder:[]}]
at org.skife.jdbi.v2.BaseStatement.cleanup(BaseStatement.java:105)
at org.skife.jdbi.v2.Query.fold(Query.java:185)
at org.skife.jdbi.v2.Query.first(Query.java:262)
at org.skife.jdbi.v2.Query.first(Query.java:254)
at io.test.dao.UserDAOTest.testFindByUsername(UserDAOTest.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:125)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OPTION SQL_SELECT_LIMIT=DEFAULT' at line 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2921)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2972)
at com.mysql.jdbc.Connection.unsetMaxRows(Connection.java:5262)
at com.mysql.jdbc.Statement.realClose(Statement.java:1606)
at com.mysql.jdbc.PreparedStatement.realClose(PreparedStatement.java:1695)
at com.mysql.jdbc.ServerPreparedStatement.realClose(ServerPreparedStatement.java:891)
at com.mysql.jdbc.ServerPreparedStatement.close(ServerPreparedStatement.java:453)
at org.skife.jdbi.v2.DefaultStatementBuilder.close(DefaultStatementBuilder.java:63)
at org.skife.jdbi.v2.Cleanables$StatementBuilderCleanable.cleanup(Cleanables.java:218)
at org.skife.jdbi.v2.BaseStatement$StatementCleaningCustomizer.cleanup(BaseStatement.java:127)
at org.skife.jdbi.v2.BaseStatement.cleanup(BaseStatement.java:102)
... 34 more

Brian McCallister

unread,
Jul 11, 2014, 4:22:50 PM7/11/14
to jd...@googlegroups.com
This is bizarre, I have no idea why mysql is changing things underneat
you, but this is something in the mysql driver :-(
> --
> You received this message because you are subscribed to the Google Groups
> "jDBI" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jdbi+uns...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages