JDBC Driver for Amazon Redshift

Build 24.0.9060

Columns

You can use the getColumns method of the DatabaseMetaData interface to retrieve column information. You can restrict the results by the table name. The code example below retrieves the column names for the "sales_db"."public".Orders table:

String connectionString = "jdbc:redshift:User=admin;Password=admin;Database=dev;Server=examplecluster.my.us-west-2.redshift.amazonaws.com;Port=5439;";

Connection conn = DriverManager.getConnection(connectionString);
DatabaseMetaData table_meta = conn.getMetaData();
ResultSet rs = table_meta.getColumns("sales_db","public","Orders", null);
while(rs.next()){
  System.out.println(rs.getString("COLUMN_NAME")); 
}
The getColumns method returns the following columns:

Column NameData TypeDescription
TABLE_CATStringThe database name.
TABLE_SCHEMStringThe table schema.
TABLE_NAMEStringThe table name.
COLUMN_NAMEStringThe column name.
DATA_TYPEintThe data type identified by the value of a constant defined in java.sql.Types.
TYPE_NAMEStringThe data type name used by the driver.
COLUMN_SIZEintThe length in characters of the column or the numeric precision.
BUFFER_LENGTHintThe buffer length.
DECIMAL_DIGITSintThe column scale or number of digits to the right of the decimal point.
NUM_PREC_RADIXintThe radix, or base.
NULLABLEintWhether the column can contain null as defined by the following JDBC DatabaseMetaData constants: columnNoNulls (0) or columnNullable (1).
REMARKSStringThe column description.
COLUMN_DEFStringThe default value for the column.
SQL_DATA_TYPEintReserved by the specification.
SQL_DATETIME_SUBintReserved by the specification.
CHAR_OCTET_LENGTHintThe maximum length of binary and character-based columns.
ORDINAL_POSITIONintThe column index, starting at 1.
IS_NULLABLEStringWhether a null value is allowed: YES or NO.
SCOPE_CATALOGStringThe table catalog that is the scope of a reference attribute.
SCOPE_SCHEMAStringThe table schema that is the scope of a reference attribute.
SCOPE_TABLEStringThe table name that is the scope of a reference attribute.
SOURCE_DATA_TYPEintThe source type of a distinct type. Or, a user-generated Ref type. If DATA_TYPE is not DISTINCT, this value is null. If a user-generated Ref, this value is null.
IS_AUTOINCREMENTStringWhether the column value is assigned by Amazon Redshift in fixed increments.
IS_GENERATEDCOLUMNStringWhether the column is generated: YES or NO.

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 24.0.9060