Read ResultSet MetaData and DatabaseMetaData :
- Once you have the ResultSet or Connection objects, you can obtain the Meta Data about the database or the query
- This gives valuable information about thedata that you are retrieving or thedatabase that you are using
ResultSetMetaData rsMeta = rs.getMetaData();
DatabaseMetaData dbmetadata = connection.getMetaData();
- There are approximately 150 methods in the DatabaseMetaData class.
- Both the ResultSetMetaData and the DatabaseMetaData provide extremely useful information to a developer about the ResultSet they have and the database that they using and DatabaseMetaData
Once you have the ResultSet or Connection objects, you can obtain the Meta Data about the database or the query
This gives valuable information about the data that you are retrieving or the database that you are using
ResultSetMetaData rsMeta = rs.getMetaData();
DatabaseMetaData dbmetadata = connection.getMetaData();
There are approximately 150 methods in the DatabaseMetaData class.
Both the ResultSetMetaData and the DatabaseMetaData provide extremely useful information to a developer about the ResultSet they have and the database that they are using.
ResultSetMetaData meta = rs.getMetaData();
//Return the column count
int iColumnCount = meta.getColumnCount();
for (int i =1 ; i <= iColumnCount ; i++)
{
System.out.println(“Column Name: " + meta.getColumnName(i));
System.out.println(“Column Type" + meta.getColumnType(i));
System.out.println("Display Size: " + meta.getColumnDisplaySize(i) );
System.out.println("Precision: " + meta.getPrecision(i));
System.out.println(“Scale: " + meta.getScale(i) );
}
The getColumnCount() method of the ResultSetMetaData Object is very useful for looping through a resultSet. By using it you can create dynamic code that isindependent on the query that you are running.
Posted in: