Interface ResultSetMetaData, resultsetmetadata

Source: Internet
Author: User

Interface ResultSetMetaData, resultsetmetadata

Definition:
public interface ResultSetMetaData extends Wrapper
Can be used to obtain information aboutResultSetThe object of the column type and attribute information in the object. Create the following code snippet:ResultSetObject rs, createResultSetMetaDataObject rsmd, and use rsmd to find the number of rs columns, and whether the first column in rs can beWHEREClause.
 
 
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.