英文:
Spring boot JPA nativeQuery Incorrect syntax near @P0
问题
@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: 在“@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);
英文:
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.
@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);
the error I am getting is
com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '@P0'.
If I write the path manually it will work
@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);
答案1
得分: 1
'@P0'是您的RowCountToDisplay参数... 可能尝试在参数周围加上括号
INSERT INTO dbo.images (imageblob) (SELECT * FROM OPENROWSET (BULK (?), SINGLE_BLOB) imageblol) SELECT CAST(scope_identity() AS int);
", nativeQuery = true)
英文:
'@P0' is your RowCountToDisplay parameter ... Maybe try to place parenthesis around the argument
INSERT INTO dbo.images (imageblob)(SELECT * FROM OPENROWSET (BULK (?), SINGLE_BLOB) imageblol) SELECT CAST(scope_identity() AS int);"
, nativeQuery = true)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论