liquibase.exception.DatabaseException: Error executing SQL select user_name(): Incorrect syntax near the keyword 'select'.

JIRA | Consultant Leon | 7 months ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    This method uses a Call statement, which is not supported for sybase when executing select user_name() , Sybase requires a prepared statement to be used here. Call statement should only be used to call a stored procedure, not to run a regular 'select' This page put me on the right track: https://sourceforge.net/p/jtds/discussion/104389/thread/102edfcd/ protected String getConnectionSchemaName() { if (connection == null || connection instanceof OfflineConnection) { return null; } try { String currentSchemaStatement = getConnectionSchemaNameCallStatement(); return ExecutorService.getInstance().getExecutor(this). queryForObject(new RawCallStatement(currentSchemaStatement), String.class); } catch (Exception e) { LogFactory.getLogger().info("Error getting default schema", e); } return null; } I just ran this in the debugger and arrived at line: public Object query(final SqlStatement sql, final ResultSetExtractor rse, final List<SqlVisitor> sqlVisitors) throws DatabaseException { if (sql instanceof CallableSqlStatement) { return execute(new QueryCallableStatementCallback(sql, rse), sqlVisitors); } return execute(new QueryStatementCallback(sql, rse, sqlVisitors), sqlVisitors); } As it's instanceof CallableSqlStatement it executes the QueryCallableStatementCallback which throws exception as per below. When I evaluate the execute QueryStatementCallback it succeeds and returns 'dbo' as expected! Error getting default schema {liquibase:133} liquibase.exception.DatabaseException: Error executing SQL select user_name(): Incorrect syntax near the keyword 'select'. at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:88) at liquibase.executor.jvm.JdbcExecutor.query(JdbcExecutor.java:117) at liquibase.executor.jvm.JdbcExecutor.query(JdbcExecutor.java:128) at liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:136) at liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:151) at liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:146) at liquibase.database.AbstractJdbcDatabase.getConnectionSchemaName(AbstractJdbcDatabase.java:324) at liquibase.database.AbstractJdbcDatabase.getDefaultSchemaName(AbstractJdbcDatabase.java:305) at liquibase.database.AbstractJdbcDatabase.toString(AbstractJdbcDatabase.java:881) at liquibase.executor.jvm.JdbcExecutor.query(JdbcExecutor.java:117) at liquibase.executor.jvm.JdbcExecutor.query(JdbcExecutor.java:128) at liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:136) at liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:151) at liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:146) at liquibase.database.AbstractJdbcDatabase.getConnectionSchemaName(AbstractJdbcDatabase.java:324) at liquibase.database.AbstractJdbcDatabase.getDefaultSchemaName(AbstractJdbcDatabase.java:305) at liquibase.changelog.ChangeLogParameters.<init>(ChangeLogParameters.java:54) at liquibase.Liquibase.<init>(Liquibase.java:104)

    JIRA | 7 months ago | Consultant Leon
    liquibase.exception.DatabaseException: Error executing SQL select user_name(): Incorrect syntax near the keyword 'select'.

    Root Cause Analysis

    1. liquibase.exception.DatabaseException

      Error executing SQL select user_name(): Incorrect syntax near the keyword 'select'.

      at liquibase.executor.jvm.JdbcExecutor.execute()
    2. Liquibase Core
      Liquibase.<init>
      1. liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:88)
      2. liquibase.executor.jvm.JdbcExecutor.query(JdbcExecutor.java:117)
      3. liquibase.executor.jvm.JdbcExecutor.query(JdbcExecutor.java:128)
      4. liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:136)
      5. liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:151)
      6. liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:146)
      7. liquibase.database.AbstractJdbcDatabase.getConnectionSchemaName(AbstractJdbcDatabase.java:324)
      8. liquibase.database.AbstractJdbcDatabase.getDefaultSchemaName(AbstractJdbcDatabase.java:305)
      9. liquibase.database.AbstractJdbcDatabase.toString(AbstractJdbcDatabase.java:881)
      10. liquibase.executor.jvm.JdbcExecutor.query(JdbcExecutor.java:117)
      11. liquibase.executor.jvm.JdbcExecutor.query(JdbcExecutor.java:128)
      12. liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:136)
      13. liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:151)
      14. liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:146)
      15. liquibase.database.AbstractJdbcDatabase.getConnectionSchemaName(AbstractJdbcDatabase.java:324)
      16. liquibase.database.AbstractJdbcDatabase.getDefaultSchemaName(AbstractJdbcDatabase.java:305)
      17. liquibase.changelog.ChangeLogParameters.<init>(ChangeLogParameters.java:54)
      18. liquibase.Liquibase.<init>(Liquibase.java:104)
      18 frames