How to check that a ResultSet contains a specifically named field?

后端 未结 5 1049
广开言路
广开言路 2020-12-29 22:04

Having rs, an instance of java.sql.ResultSet, how to check that it contains a column named \"theColumn\"?

5条回答
  •  星月不相逢
    2020-12-29 23:11

    Try using the method ResultSet#findColumn(String)

    private boolean isThere(ResultSet rs, String column)
    {
      try
      {
        rs.findColumn(column);
        return true;
      } catch (SQLException sqlex)
      {
        logger.debug("column doesn't exist {}", column);
      }
      return false;
    }
    

提交回复
热议问题