Java调用带有varbinary参数类型的存储过程。

huangapple 未分类评论44阅读模式
英文:

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."

huangapple
  • 本文由 发表于 2020年4月9日 03:09:27
  • 转载请务必保留本文链接:https://java.coder-hub.com/61108217.html
匿名

发表评论

匿名网友

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

确定