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

标签 sql-server grails

我正在Grails 3.1.1项目中使用Microsoft数据库,现在我仅使用脚手架来管理数据。每当我尝试呈现 Controller 的索引页时,我都会遇到错误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}

最佳答案

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

关于sql-server - Grails SQLServerException Microsoft数据库 'limit'附近的语法不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35920047/

相关文章:

c# - 如何将服务器数据库复制到我的本地机器以生成脚本

sql-server - 通过比较 4 个不同的行来提取数据

sql-server - SqlException 超时已过期但未达到

grails - Grails中的外部用户域

hibernate - 嵌套的findAllBy *

带有片段参数的 Grails render()

c# - 在 C# 中确定 SQL 查询参数的数据类型

sql - 使用字符串输入在表中插入多个值

grails - 在 Grails 中定义可选(多个)数据源

grails - Grails:当我重新编译文件时(使用数据源时)服务器崩溃