What Is the Relationship of ResultSetMetaData to Other Objects? JDBC

Before delving into the solution, let’s take a look at the relationships between important low-level interfaces and classes.

Figure Relationships between important low-level interfaces and classes

Figure Relationships between important low-level interfaces and classes

To connect to a database, you use an instance of the Connection class. Then, to find out the names of the database tables and fields, you need to get an instance of the DatabaseMetaData class from the connection. Next, to issue a query, you compose the SQL query string and use the Connection to create a Statement class. By executing the statement, you obtain a ResultSet class, and to find out the names of the column rows in that ResultSet, you must obtain an instance of the ResultsetMetaData object.

To obtain the ResultSet metadata, follow these steps:

  1. To connect to a database, you use an instance of the Connection object.
  2. To find out the names of the database schemas/tables/columns, you get an instance of the DatabaseMetaData object from the Connection.
  3. To issue a query, you compose the SQL query string and use the Connection to create a Statement.
  4. By executing the statement, you obtain a ResultSet object.
  5. Finally, to find out the names of the column rows in that ResultSet, you obtain an instance of the ResultsetMetaData object.

What does ResultSetMetaData provide? ResultSetMetaData objects can be used to get information about the types and properties of the columns in a ResultSet object. ResultSetMetaData encapsulates the column’s information—such as the number of columns, their names, and the column data type and its precision—contained in a ResultSet. ResultSetMetaData provides many methods to deal with the column’s information; for example, the getColumnName() method of the ResultSetMetaData object returns the column’s name in the ResultSet.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JDBC Topics