一,现在已经返回了结果集,接下来是对返回数据的分析
ResultSet.next()只不过是对rowData集合的操作
public synchronized boolean next() throws SQLException {
checkClosed();
if (this.onInsertRow) {
this.onInsertRow = false;
}
if (this.doingUpdates) {
this.doingUpdates = false;
}
boolean b;
if (!reallyResult()) {
throw SQLError.createSQLException(
Messages
.getString("ResultSet.ResultSet_is_from_UPDATE._No_Data_115"),
SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor()); //$NON-NLS-1$
}
if (this.thisRow != null) {
this.thisRow.closeOpenStreams();
}
if (this.rowData.size() == 0) {
b = false;
} else {
//下一行数据
this.thisRow = this.rowData.next();
if (this.thisRow == null) {
b = false;
} else {
clearWarnings();
b = true;
}
}
setRowPositionValidity();
return b;
}
以ResultSet.getByte("")获取数据为例
//findColumn()方法,会找到相应的索引位置
public byte[] getBytes(String columnName) throws SQLException {
return getBytes(findColumn(columnName));
}
public byte getByte(int columnIndex) throws SQLException {
if (!this.isBinaryEncoded) {
//先通getString获取
String stringVal = getString(columnIndex);
if (this.wasNullFlag || (stringVal == null)) {
return 0;
}
return getByteFromString(stringVal, columnIndex);
}
return getNativeByte(columnIndex);