MySQL jdbc ResultSet
所属分类 mysql
浏览量 776
mysql-connector-java-5.1.30.jar
com.mysql.jdbc.ResultSetImpl
public String getString(String columnName) throws SQLException {
return getString(findColumn(columnName));
}
this.columnLabelToIndex = new TreeMap< String, Integer>(String.CASE_INSENSITIVE_ORDER);
TreeMap key 忽略大小写
public int findColumn(String columnName) throws SQLException {
synchronized (checkClosed().getConnectionMutex()) {
Integer index;
if (!this.hasBuiltIndexMapping) {
buildIndexMapping();
}
index = this.columnToIndexCache.get(columnName);
if (index != null) {
return index.intValue() + 1;
}
index = this.columnLabelToIndex.get(columnName);
if (index == null && this.useColumnNamesInFindColumn) {
index = this.columnNameToIndex.get(columnName);
}
if (index == null) {
index = this.fullColumnNameToIndex.get(columnName);
}
if (index != null) {
this.columnToIndexCache.put(columnName, index);
return index.intValue() + 1;
}
// Try this inefficient way, now
for (int i = 0; i < this.fields.length; i++) {
if (this.fields[i].getName().equalsIgnoreCase(columnName)) {
return i + 1;
} else if (this.fields[i].getFullName()
.equalsIgnoreCase(columnName)) {
return i + 1;
}
}
throw SQLError.createSQLException(Messages.getString("ResultSet.Column____112")
+ columnName
+ Messages.getString("ResultSet.___not_found._113"), //$NON-NLS-1$ //$NON-NLS-2$
SQLError.SQL_STATE_COLUMN_NOT_FOUND, getExceptionInterceptor());
}
}
// Builds a hash between column names and their indices for fast retrieval.
public void buildIndexMapping() throws SQLException {
int numFields = this.fields.length;
this.columnLabelToIndex = new TreeMap< String, Integer>(String.CASE_INSENSITIVE_ORDER);
this.fullColumnNameToIndex = new TreeMap< String, Integer>(String.CASE_INSENSITIVE_ORDER);
this.columnNameToIndex = new TreeMap< String, Integer>(String.CASE_INSENSITIVE_ORDER);
// We do this in reverse order, so that the 'first' column
// with a given name ends up as the final mapping in the
// hashtable...
//
// Quoting the JDBC Spec:
//
// "Column names used as input to getter
// methods are case insensitive. When a getter method is called with a
// column
// name and several columns have the same name, the value of the first
// matching column will be returned. "
//
for (int i = numFields - 1; i >= 0; i--) {
Integer index = Integer.valueOf(i);
String columnName = this.fields[i].getOriginalName();
String columnLabel = this.fields[i].getName();
String fullColumnName = this.fields[i].getFullName();
if (columnLabel != null) {
this.columnLabelToIndex.put(columnLabel, index);
}
if (fullColumnName != null) {
this.fullColumnNameToIndex.put(fullColumnName, index);
}
if (columnName != null) {
this.columnNameToIndex.put(columnName, index);
}
}
// set the flag to prevent rebuilding...
this.hasBuiltIndexMapping = true;
}
上一篇
下一篇
GO printf 格式化输出
mybatis 结果集处理
Mybatis常用工具类
key忽略大小写的TreeMap
go select 与 定时器
go类型转换和断言