请向我解释
之间的不同之处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 :(得分: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 ...;
}
尝试这个,让我们知道它是否有效,以便我们可以尝试别的东西