Reputation: 203
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);
Upvotes: 1
Views: 3898
Reputation: 92
'@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)
Upvotes: 1