Grails SQLServerException Microsoft数据库'limit'附近的语法不正确

时间:2016-03-10 15:00:42

标签: sql-server grails

我正在使用Grails 3.1.1项目中的Microsoft数据库,现在我只是使用脚手架来管理数据。每当我尝试渲染控制器的索引页时,我遇到错误Incorrect syntax near 'limit'.。 这是完整的错误日志:

org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not extract ResultSet; uncategorized SQLException for SQL [n/a]; SQL state [S0001]; error code [102]; Incorrect syntax near 'limit'.; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'limit'.
    at inkinventory.IsInkInventoryController.index(IsInkInventoryController.groovy:13) ~[main/:na]
    at grails.transaction.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:96) ~[grails-core-3.1.1.jar:3.1.1]
    at grails.transaction.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:93) ~[grails-core-3.1.1.jar:3.1.1]
    at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.groovy:53) ~[spring-security-core-3.0.3.jar:na]
    at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.groovy:62) ~[spring-security-core-3.0.3.jar:na]
    at grails.plugin.springsecurity.web.SecurityRequestHolderFilter.doFilter(SecurityRequestHolderFilter.groovy:58) ~[spring-security-core-3.0.3.jar:na]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_73]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_73]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_73]
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'limit'.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216) ~[sqljdbc-4.jar:na]
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1515) ~[sqljdbc-4.jar:na]
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:404) ~[sqljdbc-4.jar:na]
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:350) ~[sqljdbc-4.jar:na]
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696) ~[sqljdbc-4.jar:na]
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715) ~[sqljdbc-4.jar:na]
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180) ~[sqljdbc-4.jar:na]
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155) ~[sqljdbc-4.jar:na]
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:285) ~[sqljdbc-4.jar:na]
    at grails.orm.PagedResultList.<init>(PagedResultList.java:43) ~[grails-datastore-gorm-hibernate4-5.0.1.RELEASE.jar:na]
    ... 9 common frames omitted

它指向的代码行为错误:

def index(Integer max) {
        params.max = Math.min(max ?: 10, 100)
        respond IsInkInventory.list(params), model:[isInkInventoryCount: IsInkInventory.count()]
    }

这是数据库配置:

dataSources:
    dataSource:
        pooled: true
        jmxExport: true
        driverClassName: org.h2.Driver
        username: sa
        password:
    sqlDB:
        pooled: true
        jmxExport: true
        driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
        username: {un}
        password: {pw}

2 个答案:

答案 0 :(得分:0)

我删除了h2数据库连接,这似乎解决了这个问题。我假设由于两个数据连接之间存在两种不同的语法,因此无法确定如何生成查询

答案 1 :(得分:0)

  1. build.gradle中设置以下插件:

    compile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '8.4.1.jre8'
    
  2. application.yml中添加driverClassNamedialect,如下所示:

    dataSource:
        pooled: true
        jmxExport: true
        driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
        username: admin
        password: '123456'
        dialect: org.hibernate.dialect.SQLServer2012Dialect
    
  3. 运行项目,错误将得到解决。