首页  

postgresql jdbc 驱动 ResultSet 取值     所属分类 PostgreSQL 浏览量 848
postgresql-42.3.3.jar

java.sql.ResultSet.getString(String)
String getString(String columnLabel) throws SQLException;

columnLabel the label for the column specified with the SQL AS clause.  
If the SQL AS clause was not specified, then the label is the name of the column

大小写 是否敏感


connection.isColumnSanitiserDisabled()
false 字段名全部转为小写

根据字段名 获取 字段索引时  ,转成 大小写 获取

PostgreSQL 默认 字段名大小写不敏感





org.postgresql.jdbc.PgResultSet 

public String getString(String columnName) throws SQLException {
    return getString(findColumn(columnName));
}
  
  public @NonNegative int findColumn(String columnName) throws SQLException {
    checkClosed();

    int col = findColumnIndex(columnName);
    if (col == 0) {
      throw new PSQLException(
          GT.tr("The column name {0} was not found in this ResultSet.", columnName),
          PSQLState.UNDEFINED_COLUMN);
    }
    return col;
  }
  
 private @NonNegative int findColumnIndex(String columnName) {
    if (columnNameIndexMap == null) {
      if (originalQuery != null) {
        columnNameIndexMap = originalQuery.getResultSetColumnNameIndexMap();
      }
      if (columnNameIndexMap == null) {
        columnNameIndexMap = createColumnNameIndexMap(fields, connection.isColumnSanitiserDisabled());
      }
    }

    Integer index = columnNameIndexMap.get(columnName);
    if (index != null) {
      return index;
    }

    index = columnNameIndexMap.get(columnName.toLowerCase(Locale.US));
    if (index != null) {
      columnNameIndexMap.put(columnName, index);
      return index;
    }

    index = columnNameIndexMap.get(columnName.toUpperCase(Locale.US));
    if (index != null) {
      columnNameIndexMap.put(columnName, index);
      return index;
    }

    return 0;
  }
  
  
The JDBC spec says when you have duplicate columns names,
the first one should be returned. So load the map in
reverse order so the first ones will overwrite later ones.
    
    
  public static Map<String, Integer> createColumnNameIndexMap(Field[] fields,
      boolean isSanitiserDisabled) {
    Map<String, Integer> columnNameIndexMap = new HashMap<String, Integer>(fields.length * 2);
    // The JDBC spec says when you have duplicate columns names,
    // the first one should be returned. So load the map in
    // reverse order so the first ones will overwrite later ones.
    for (int i = fields.length - 1; i >= 0; i--) {
      String columnLabel = fields[i].getColumnLabel();
      if (isSanitiserDisabled) {
        columnNameIndexMap.put(columnLabel, i + 1);
      } else {
        columnNameIndexMap.put(columnLabel.toLowerCase(Locale.US), i + 1);
      }
    }
    return columnNameIndexMap;
  }
  
  


上一篇     下一篇
c语言获取UUID

UUID简介

temporal 获取集群信息 关键代码

temporal 获取 namespace信息 关键代码和堆栈信息

temporal 重要表说明

Temporal Clusters