我正在尝试从表Type
获取对象,但查询返回空ResultSet:
public Type get(String id) {
Type type = null;
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append("SELECT * FROM ");
queryBuilder.append(TABLE_NAME);
queryBuilder.append(" WHERE ");
queryBuilder.append(TYPE + "=?;");
String query = queryBuilder.toString();
try {
PreparedStatement statement = connection.prepareStatement(query);
statement.setString(1, id);
ResultSet result = statement.executeQuery();
if(result.next()){
type = new Type(id,
result.getString(DEFINITION));
}
} catch (SQLException e) {
e.printStackTrace();
}
return type;
}
TABLE_NAME和TYPE是“类型”和“类型”。
如果我在MySQL控制台中尝试使用相同的参数进行查询,它将返回结果。怎么了?