简体   繁体   中英

Is interaction between ResultSet and ResultSetMetaData one-way?

A colleague of mine pulled some code from the web that does something like the following:

ResultSetMetaData rsmd = rs.getMetaData();
while (rs.next()) {
  count = rsmd.getColumnCount();
  validateSame(firstRowCount, count);
}

This implies that the RSMD is maintaining an internal reference to the ResultSet and the column count could vary by row.

It seems intuitive to me that there would be one set of metadata per RS, and I'd like to refactor this code out, but I haven't been able to verify this in the Java documentation or get at it through Google searches. Could someone please confirm or deny that the metadata is constant?

An SQL result set is a table whose structure is defined entirely by the query and the underlying table(s) being queried. It cannot vary row by row. You can refactor this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM