db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Spezifikum <i...@spezifikum.com>
Subject Re: Getting the table structure programmatically
Date Sun, 31 Jul 2011 17:20:17 GMT
Am 28.07.2011 11:03, schrieb Knut Anders Hatlen:
> Spezifikum<info@spezifikum.com>  writes:
>
>> Hi
>> i have to read the structure of some tables i created and display that
>> in my HTML pages. So i tried to do something like
>> execute( "describe myTable" ) and get an SQL exception (invalid syntax).
>> Should i instead query some system tables?
> Hi Malte,
>
> Essentially, it just calls
> conn.getMetaData().getColumns(null, schema, table, null) and displays
> the following columns from the returned ResultSet: TABLE_SCHEM,
> TABLE_NAME, COLUMN_NAME, TYPE_NAME, DECIMAL_DIGITS, NUM_PREC_RADIX,
> COLUMN_SIZE, COLUMN_DEF, CHAR_OCTET_LENGTH, IS_NULLABLE
>
Hi Knut,
thanks a lot, it works! As a first quick test i used:
             DatabaseMetaData dmd = conn.getMetaData( );
             ResultSet cols = dmd.getColumns( null, "MyDB", "MYTABLE", 
null );
             while( cols.next() ) {
                 String value = cols.getString( 1 );
                 System.out.println( value );
                 ...
            }

I wouldn't have found the DatabaseMetaData class without some help, so 
just thanks again.

Malte


Mime
View raw message