Interface ResultSetMetaData, resultsetmetadata
Definition:
public interface ResultSetMetaData extends Wrapper
Can be used to obtain information aboutResultSet
The object of the column type and attribute information in the object. Create the following code snippet:ResultSet
Object rs, createResultSetMetaData
Object rsmd, and use rsmd to find the number of rs columns, and whether the first column in rs can beWHERE
Clause.
For example:
Package ResultSetMetaData;
Import java. SQL. connection; import java. SQL. driverManager; import java. SQL. resultSet; import java. SQL. resultSetMetaData; import java. SQL. SQLException; import java. SQL. statement; public class test {public static void main (String [] args) {Connection conn = null; Statement stmt = null; try {Class. forName ("oracle. jdbc. driver. oracleDriver "); conn = DriverManager. getConnection ("jdbc: oracle: thin: @ localhost: 1521: oracle12c", "c # scott", "tiger"); stmt = conn. createStatement (); // create the ResultSet object rs ResultSet rs = stmt.exe cuteQuery ("select * from test"); // create the ResultSetMetaData object rsmd ResultSetMetaData rsmd = rs. getMetaData (); // use rsmd to find the number of columns of rs int numberOfColumns = rsmd. can the first column in getColumnCount (); // rs use boolean B = rsmd IN THE WHERE clause. isSearchable (1); System. out. println ("total data" + numberOfColumns + "columns"); System. out. println ("Can the first column in rs be used in the WHERE clause" + B);} catch (ClassNotFoundException e) {e. printStackTrace ();} catch (SQLException e) {e. printStackTrace ();}}}
We can also get more information:
String getCatalogName (int column)
Obtains the table directory name of a specified column. String getColumnClassName (int column) if the method ResultSet. getObject is called to obtain the value from the column, a fully qualified name of the Java class that constructs the instance is returned. Int getColumnCount () returns the number of columns in this ResultSet object. Int getColumnDisplaySize (int column) indicates the maximum standard width of a specified column, in characters. String getColumnLabel (int column) gets the recommended title of the specified column used to print the output and display. String getColumnName (int column) gets the name of the specified column. Int getColumnType (int column) gets the SQL type of the specified column. String getColumnTypeName (int column) gets the database-specific type name of the specified column. Int getPrecision (int column) obtains the width of a specified column. Int getScale (int column) obtains the number of digits to the right of the decimal point of the specified column. String getSchemaName (int column) obtains the table mode of the specified column. String getTableName (int column) gets the name of the specified column. Boolean isAutoIncrement (int column) indicates whether to automatically number a specified column. Boolean isCaseSensitive (int column) indicates whether the column is case sensitive. Boolean isCurrency (int column) indicates whether the specified column is a hash code value. Boolean isDefinitelyWritable (int column) indicates whether the write operation on the specified column is clear. Int isNullable (int column) indicates whether the value in the specified column can be null. Boolean isReadOnly (int column) indicates whether the specified column cannot be written. Boolean isSearchable (int column) indicates whether the specified column can be used in the where clause. Boolean isSigned (int column) indicates whether the value in the specified column carries a plus or minus sign. Boolean isWritable (int column) indicates whether the write operation on the specified column can be successful.