wood burning stoves 2.0*
The moose likes JDBC and the fly likes Ms SQL Decimal Field Conversion into binary in JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Ms SQL Decimal Field Conversion into binary in JDBC" Watch "Ms SQL Decimal Field Conversion into binary in JDBC" New topic
Author

Ms SQL Decimal Field Conversion into binary in JDBC

Zubair Safenet
Greenhorn

Joined: Jun 21, 2012
Posts: 1
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]
Wei Dai
Ranch Hand

Joined: Jun 22, 2005
Posts: 86
You can try to convert Decimal into varchar first, then encrypt it.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1106

Welcome to the ranch Zubair, I hope you find us helpful (unfortunatly I am not going to be )
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ms SQL Decimal Field Conversion into binary in JDBC
 
Similar Threads
Dao integration unit test issue (rollback or temporary database)
Large Binary Objects
conversions
stuck up in the problem
problem converting to binary