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);
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