2013-04-05 114 views
0

我有以下函數定義:長轉換爲原始JDBC

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]); 
    } 
} 

一個客戶通過我long[],這不會改變。我所說的Oracle數據庫將數據存儲爲RAW。數據看起來是正確的持久。但是,在檢索時,我會得到無法理解的結果。

檢索代碼:

... 
while(results.next()) 
{  
    String s = new String(results.getBytes(1)); 
}  
... 

這不會給已傳遞到數據庫所需的長期價值。我該如何解決這個問題?也就是說,我將long轉換爲RAW的方式存在問題,還是存在於我的檢索代碼中?

回答

3

看起來你在調用一個不建議使用的構造函數,它另外僅用於byte數組和String。我認爲適當的方法是這樣的:

toReturn[i] = RAW.newRAW(Long.toHexString(toConvert[i])); 

編輯:如果resultsIterator<RAW>,該while -loop應改爲這樣:

while(results.hasNext()) { 
    String s = new String(results.next().getBytes()); 
} 

如果resultsRAW - 陣列,你應該這樣做:

for(RAW result : results) { 
    String s = new String(result.getBytes()); 
} 
+0

我的檢索代碼是一樣的嗎? – Woot4Moo 2013-04-05 16:12:35

+0

@ Woot4Moo對於您的檢索代碼,我沒有仔細查看,對不起。我刪除了我以前的評論。 – 2013-04-05 16:34:15