2017-09-22 123 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 ...; 

}

试试这个,让我们知道,如果它工作与否,这样我们就可以尝试别的东西