0

Trying to get the column's metadata from connection/database metadata. Any way to use rs.beforeFirst() or any alternative to move back the cursor?

Following is code snippet:

ResultSet rs= read_conn.getMetaData().getColumns(null, null, 
sourceTableName.toUpperCase(), null);

while (rs.next()){ ... }

rs.beforeFirst();  /* Error:17075. Assuming DatabaseMetaData's resultset is 
ResultSet.TYPE_FORWARD_ONLY*/

Reference:

  • DatabaseMetaData

  • Connection is opened/configured using JNDI DataSources on Tomcat 7/8 and WebLogic 11/12.

N00b Pr0grammer
  • 4,503
  • 5
  • 32
  • 46

1 Answers1

1

Fromm ResultSet Java docs

A default ResultSet object is not updatable and has a cursor that moves forward only.

So rs.beforeFirst() should be used first like this:

rs.beforeFirst();
while ( rs.next()) {
   String id = rs.getString("id");
}
N00b Pr0grammer
  • 4,503
  • 5
  • 32
  • 46
M Sach
  • 33,416
  • 76
  • 221
  • 314
  • Requirement is, iterate the DatabaseMetaData related getColumns multiple times. So any way to change default settings from forwards-only to scroll-insensitive, specific to one generated by: read_conn.getMetaData().getColumns(...); – user983549 Sep 19 '16 at 07:21