Reputation: 24336
I have the following function defined:
private RAW[] longToRaw(long[] toConvert) throws SQLException
{
final RAW[] toReturn = new RAW(toConvert.length);
for(int i = 0; i <toReturn.length;i++)
{
toReturn[i] = new RAW(toConvert[i]);
}
}
A client passes me long[]
and this will not change. The Oracle database I talk to stores data as RAW
. The data appears to be correctly persisted. However, upon retrieval I get unintelligible results.
Retrieval code:
...
while(results.next())
{
String s = new String(results.getBytes(1));
}
...
This does not give the desired long value that was passed into the database. How can I resolve this issue? That is to say is the issue in the way I convert long
to RAW
or is it in my retrieval code?
Upvotes: 0
Views: 669
Reputation: 4878
It appears you're calling a deprecated constructor, which additionally is meant for byte
arrays and String
s only. I believe the appropriate way would be like this:
toReturn[i] = RAW.newRAW(Long.toHexString(toConvert[i]));
EDIT: If results
is an Iterator<RAW>
, the while
-loop should be changed to this:
while(results.hasNext()) {
String s = new String(results.next().getBytes());
}
If results
is a RAW
-array, you should do it like this:
for(RAW result : results) {
String s = new String(result.getBytes());
}
Upvotes: 3