Ms SQL Decimal Field Conversion into binary in JDBC
Joined: Jun 21, 2012
I am writing a JDBC application. My Task is to get the data from SQL server encrypt them and then store them in another table as varbinary field. I have successfully converted all sql data types to binary except decimal field.
I am using getBytes() method of JDBC to get the bytes for this decimal field. But the bytes I am receiving are not valid bytes for example I am running one query in sql which will convert decimal to binary as
declare @deci decimal(18,2)
set @deci = 2.33
print cast(@deci as varbinary)
as a result I get -- 0x12020001E9000000 (for my application to work properly I need this binary on JDBC side) : (5 bytes)
but on the JDBC side I get bytes as (for the same value) -- 2,1,-23,3,0 (5 bytes)(I am printing the value of each byte)
can anybody help me to understand the difference?? and how to convert these JDBC bytes to above varbinary
Thanks in advance
[Rob: Removed size tags]
Joined: Jun 22, 2005
You can try to convert Decimal into varchar first, then encrypt it.