英文:
Java call stored procedure with parameter type of varbinary
问题
@Query(value = "EXEC dbo.testUser :name, :Application, :test_id", nativeQuery = true)
public Object callTestProcedure(@Param("name") String name, @Param("Application") String Application, @Param("test_id") byte[] test_id);
callTestProcedure("Truview", "TruViewDataHub", Base64.decodeBase64("0x01050000000000051500000011D81D73D36F037181499C550F1A0000"));
String hex = String.format("%040x", new BigInteger(1, "0x01050000000000051500000011D81D73D36F037181499C550F1A0000".getBytes("UTF-8")));
callTestProcedure("Truview", "TruViewDataHub", hex);
Please note that the above translations are based on the code portions you provided. If you encounter any issues, you might need to review the code logic and the stored procedure for any potential errors.
英文:
Would like to query does anyone have idea how to call stored procedure with three parameters(first two are varchar and third one is varbinary) in java, I tried to call it through jpa's nativequery
stored procedure calling script from SQL server
DECLARE @userSid as VARBINARY(100)
SET @test_id = SUSER_SID('test_account')
select @test_id;
EXEC dbo.testUser 'test','test',@test_id
Below is what I tried to execute stored procedure so far from nativequery
@Query(value = "{call testUser(:name,:Application,:test_id)}",nativeQuery=true)
public Object callTestProcedure(@Param("name") String name,@Param("Application") String Application,@Param("test_id") byte[] test_id);
Tried to call it as below..
callTestProcedure("Truview","TruViewDataHub",Base64.decodeBase64("0x01050000000000051500000011D81D73D36F037181499C550F1A0000"))
But this doesn't work, any helps will be appreciated.. thank you
updated.. also tried to convert to HEX as below
String hex=String.format("%040x", new BigInteger(1, "0x01050000000000051500000011D81D73D36F037181499C550F1A0000".getBytes("UTF-8")));
callTestProcedure("Truview","TruViewDataHub",hex);
which will cause another error "Implicit conversion from data type nvarchar to varbinary is not allowed. Use the CONVERT function to run this query."
专注分享java语言的经验与见解,让所有开发者获益!
评论