String str1=rs.getString("a"); //this is surely correct
but when do rs.getString("a") again,it is wrong and some strange error happen ,why?the "rs" still wait on the current cursor,why can't i do the
same rs.getString("a") two times?
anybody have the same experience please give me help,thx a lot!!
The ResultSet interface provides getter methods (getBoolean, getLong, and so on) for retrieving column values from the current row. Values can be retrieved using either the index number of the column or the name of the column. In general, using the column index will be more efficient. Columns are numbered from 1. For maximum portability, result set columns within each row should be read in left-to-right order, and each column should be read only once.
Basically it's saying it's not guaranteed to work, perhaps because it's not an explicit requirement of the JDBC spec.
My stock response to queries such as, "I'm doing something that I probably shouldn't be and it doesn't work or behaves strangely", is "Don't do that then!" Best practice is to call the method once and store the returned value in a variable if you need it again. As it says, do it in order too; that was a new one on me!
But I am puzzled that if the results is stream.we know
"which sentence of them is first is doesn't matter,so we can sure
the content is just fixed by the index or columnname,then why we cannot
find that content by columnname once a time?
just cannot understand.
Originally posted by Peter den Haan:
This was put in there to allow the driver to stream the results at the field level. So when you call rs.getString(2), the driver might just read the second field of the current record from the server's data stream and return that to you - with no way to go back to the first field, or even to return the field a second time.