Spring Boot JPA 原生查询语句中 @P0 附近语法错误。

huangapple go评论93阅读模式
英文:

Spring boot JPA nativeQuery Incorrect syntax near @P0

问题

  1. @Query(
  2. value = "INSERT INTO dbo.images (imageblob)(SELECT * FROM OPENROWSET (BULK ?, SINGLE_BLOB) imageblol) SELECT CAST(scope_identity() AS int);",
  3. nativeQuery = true)
  4. Integer insertImage(String path);

错误信息:

  1. com.microsoft.sqlserver.jdbc.SQLServerException: 在“@P0”附近有语法错误。

如果我手动编写路径,它会正常工作:

  1. @Query(
  2. 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);",
  3. nativeQuery = true)
  4. Integer insertImage(String path);
英文:

I am trying to run the following query from a spring boot app using Hibernate, and the problem is that in the query I need to pass the path variable from the method.

  1. @Query(
  2. value = "INSERT INTO dbo.images (imageblob)(SELECT * FROM OPENROWSET (BULK ?, SINGLE_BLOB) imageblol) SELECT CAST(scope_identity() AS int);",
  3. nativeQuery = true)
  4. Integer insertImage(String path);

the error I am getting is

  1. com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '@P0'.

If I write the path manually it will work

  1. @Query(
  2. 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);",
  3. nativeQuery = true)
  4. Integer insertImage(String path);

答案1

得分: 1

'@P0'是您的RowCountToDisplay参数... 可能尝试在参数周围加上括号

  1. INSERT INTO dbo.images (imageblob) (SELECT * FROM OPENROWSET (BULK (?), SINGLE_BLOB) imageblol) SELECT CAST(scope_identity() AS int);
  2. ", nativeQuery = true)
英文:

'@P0' is your RowCountToDisplay parameter ... Maybe try to place parenthesis around the argument

  1. INSERT INTO dbo.images (imageblob)(SELECT * FROM OPENROWSET (BULK (?), SINGLE_BLOB) imageblol) SELECT CAST(scope_identity() AS int);"
  2. , nativeQuery = true)

huangapple
  • 本文由 发表于 2020年10月2日 00:54:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/64159974.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定