java - Spring boot JPA nativeQuery @P0 附近的语法不正确
问题描述
我正在尝试使用 Hibernate 从 Spring Boot 应用程序运行以下查询,问题是在查询中我需要从方法中传递路径变量。
@Query(
value = "INSERT INTO dbo.images (imageblob)(SELECT * FROM OPENROWSET (BULK ?, SINGLE_BLOB) imageblol) SELECT CAST(scope_identity() AS int);",
nativeQuery = true)
Integer insertImage(String path);
我得到的错误是
com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '@P0'.
如果我手动编写路径它将起作用
@Query(
value = "INSERT INTO dbo.images (imageblob)(SELECT * FROM OPENROWSET (BULK 'C:\\pic\\NORMAL2-IM-1257-0001.jpeg', SINGLE_BLOB) imageblol) SELECT CAST(scope_identity() AS int);",
nativeQuery = true)
Integer insertImage(String path);
解决方案
'@P0' 是您的 RowCountToDisplay 参数...也许尝试在参数周围放置括号
INSERT INTO dbo.images (imageblob)(SELECT * FROM OPENROWSET (BULK (?), SINGLE_BLOB) imageblol) SELECT CAST(scope_identity() AS int);"
, nativeQuery = true)
推荐阅读
- powerbi - Power BI:计算列当前行的平均值除以第一行
- c++ - 如何使我的类在 Visual Studio 中像 std::array 和 std::vector 一样调试友好?
- google-cloud-platform - 对复杂对象数组的 Google Datastore 投影查询
- arrays - 如何使用 Twig 在 *.html 中打印 *.json 文件的值
- excel - 如何选择宏链接超链接旁边的单元格
- drupal-7 - MAMP 更改文档根目录需要重新导入 sql 数据库
- terraform - Terraform:模块的名称可以动态解析吗?
- python - 从表的属性创建图形
- flask - Gunicorn + Flask - @app.errorhandler(500) 被忽略?
- swiftui - SwiftUI 启动屏幕未显示