Fadi
Fadi

Reputation: 203

Spring boot JPA nativeQuery Incorrect syntax near @P0

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

Answers (1)

SinisaT90
SinisaT90

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

Related Questions