2017-09-22 30 views
0

請向我解釋型動物數據庫訪問錯誤

private boolean inUse(JDBCTemplates jdbc, BigInteger firmwareId) { 
       String query = "select * from references ref " + 
       "where ref.attr_id = 9 " + 
       "and ref.reference = ?"; 
     try { 
       s = (String) jdbc.selectForObject(query....); 
      } catch (Exception e) { 
       log.info(e.toString()); 
      } 
     return ...; 
} 

private boolean inUse(JDBCTemplates jdbc, BigInteger firmwareId) { 
       String query = "select * from references ref " + 
       "where ref.attr_id = 9 " + 
       "and ref.reference =" + firmwareId; 
     try { 
       s = (String) jdbc.selectForObject(query....); 
      } catch (Exception e) { 
       log.info(e.toString()); 
      } 
     return ...; 
} 

在第二種情況下之間,我得到一個錯誤的訪問對數據庫(jdbc.DataAccessException:錯誤是由於訪問數據庫),並在第一種情況下,一切正常。

+0

請顯示完整的錯誤! – OldProgrammer

+1

發佈完整的代碼。沒有看到完整的代碼以及如何執行它們,您的代碼片段就毫無意義。 – Strikegently

+0

jdbc.DataAccessException:由於訪問數據庫導致錯誤: –

回答

0

嘗試修改代碼這種方式,注重串查詢和參數:

private boolean inUse(JDBCTemplates jdbc, BigInteger firmwareId) { 
      String query = "select * from references ref " + 
      "where ref.attr_id = 9 " + 
      "and ref.reference ='" + firmwareId+"'";//Here might be the error 
    try { 
      s = (String) jdbc.selectForObject(query....); 
     } catch (Exception e) { 
      log.info(e.toString()); 
     } 
    return ...; 

}

試試這個,讓我們知道,如果它工作與否,這樣我們就可以嘗試別的東西