Wednesday, July 22, 2015

ResultSet and ResultSetMetaData

When we dont know what type of value the query will return, we have to use ResultSetMetaData otherwise go for ResultSet.

ResultSetMetaData.getColumnType(int column) returns a int value specifying the column type found in java.sql.Types.

ResultSetMetaData rsmd = rs.getMetaData();

int type = rsmd.getColumnType(i);

if (type == Types.VARCHAR)
    rs.getString(i);
else
    rs.getLong(i);

No comments:

Post a Comment

Home