Metadata
The term metadata sounds
officious, but it is really nothing more than extra data about some
object that would otherwise waste resources if it were actually kept
in the object. For example, simple applications do not need the name
of the columns associated with a
ResultSet
—the programmer probably knew
that when the code was written. Embedding this extra information in
the ResultSet
class is thus not considered by
JDBC’s designers to be part of the core of
ResultSet
functionality. Data such as the column
names, however, is very important to some database
programmers—especially those writing dynamic database access.
The JDBC designers provide access to this extra information—the
metadata—via the ResultSetMetaData
interface. This class specifically
provides:
The number of columns in a result set
Whether
NULL
is a valid value for a columnThe label to use for a column header
The name for a given column
The source table for a given column
The data type of a given column
Example 13-6 shows some of the source code from a command-line tool that accepts arbitrary user input and sends it to MySQL for execution. The rest of the code for this example can be found at the O’Reilly web site with the other examples from this book.
import java.sql.*; public class Exec { public static void main(String args[]) { Connection con = null; String sql = ""; for(int i=0; i<args.length; i++) { sql = sql + args[i]; if( i < args.length - 1 ) { sql ...
Get Managing & Using MySQL, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.