How do I read table metadata?

Hi
Can anyone advise me how to read the metadata in through a JDBC connection?
Specifically I am connecting to a DB2 database and reading in the table names for a given schema from the table: -
// Connect to DB and read in the table names
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT NAME FROM SYSTOOLS.HMON_ATM_INFO WHERE SCHEMA = '" + schema + "'");
while(rs.next()){
tblNames.add(rs.getString("NAME"));
Now I want to iterate through my ArrayList tblNames and use each table name to query each table's metadata, specifically the name of each field in the table and its datatype and size. Is it possible to do this through the getMetaData call something like this: -
// Got the table names so read the table metrics
Iterator<?> tnms = tblNames.iterator();
while(tnms.hasNext()){
String[] types = {"NAME"};
String tableName = (String)tnms.next();
DatabaseMetaData dbmd = conn.getMetaData();
rs = dbmd.getTables("", schema, tableName, types);
Thanks in advance
Brad

OK found how to do it in case anyone else is looking I will answer this myself: -
package db_tools;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
* @author brad
public class Db2MetricsManager {
     // jdbc Connection
     private Connection conn = null;
     private ArrayList<String> tblNames;
     // Constructors
     Db2MetricsManager(){
     Db2MetricsManager(Connection conn){
          this.conn = conn;
          tblNames = new ArrayList<String>();
     // Methods
     public ArrayList<String> getTableNames(){
          return tblNames;
     public void readTableMetricsBySchema(String schema){
          Statement stmt = null;
          try{
               // Connect to DB and read in the table names
               String[] types = {"TABLE"};
               DatabaseMetaData dbmdt = conn.getMetaData();
               ResultSet rst = dbmdt.getTables(null, schema, "%", types);
               while(rst.next()){
                    tblNames.add(rst.getString("TABLE_NAME"));
               // Got the table names so read the table metrics
               ArrayList<String> columns = new ArrayList<String>();
               Iterator<?> tnms = tblNames.iterator();
               while(tnms.hasNext()){
                    String tableName = (String)tnms.next();
                    System.out.println("TABLE_NAME = " + tableName);
                    DatabaseMetaData dbmd = conn.getMetaData();
                    ResultSet rsc = dbmd.getColumns(null, schema, tableName, "%");
                    while(rsc.next()){
                         String cn = rsc.getString("COLUMN_NAME");
                         System.out.print("COLUMN_NAME = " + cn);
                         String dt = rsc.getString("TYPE_NAME");
                         System.out.print("\t\tTYPE_NAME = " + dt);
                         int cs = rsc.getInt("COLUMN_SIZE");
                         System.out.print("\t\tCOLUMN_SIZE = " + cs);
                         System.out.println();
                         /** TODO Create a UDT to hold the metadata and add to a collection */
                    System.out.println();
          catch (SQLException sqle){
               System.err.println(sqle.getMessage());
          finally{
               if(stmt != null){
                    try{stmt.close();}catch(Exception e){};
}

Similar Messages

  • How do I read the metadata of an object in abap?

    I need to find a way to read the metadata of an object (say an internal table) in abap.  An example of what I am looking to do is that I want to get a list of all the column names of an internal table.  Any help would be greatly appreciated!
    Dustin

    Sure, use this function.
    TYPES: BEGIN OF type_item,
           f1 TYPE char30,
           f2 TYPE char30,
           f3 TYPE char30,
           f4 TYPE char30,
           END OF type_item.
    DATA:  lineitems TYPE TABLE OF type_item WITH HEADER LINE,
           fieldlist TYPE TABLE OF rstrucinfo WITH HEADER LINE.
    DATA:  syrepid TYPE sy-repid.
    syrepid = sy-repid.
    * gets all of the components of a structure
    CALL FUNCTION 'GET_COMPONENT_LIST'
      EXPORTING
        program    = syrepid
        fieldname  = 'lineitems'
      TABLES
        components = fieldlist.
    LOOP AT fieldlist.
      WRITE:/ fieldlist-compname .
    ENDLOOP.
    Regards,
    Rich Heilman

  • How to use Read table with out key fields

    Hi Experts,
    I need to retrieve the 2 internal tables data into single table.
    I have 3 common fields between the 2 tables but I don't have the Key fields. Then how to use the read table in this.
    Thanks in Advance.
    Edited by: satish4abap on Mar 10, 2010 9:39 AM

    Hi Satish,
    Key fields are nothing but the common fields with which you can pick the data from the second internal table.
    If you can paste your Internal table fields then we will be able to assit you better.
    However, in genral scenarios you can use it as below :
    In this scenario, we are putting data from 3 internal table to another single internal table.
    LOOP AT T_PRGEN INTO WA_PRGEN.
           WA_FINAL-GUID_PR       = WA_PRGEN-GUID_PR.
           WA_FINAL-ATTR20A       = WA_PRGEN-ATTR20A.
           WA_FINAL-ATTR05A       = WA_PRGEN-ATTR05A.
           WA_FINAL-ATTR05B       = WA_PRGEN-ATTR05B.
           WA_FINAL-ATTR05C       = WA_PRGEN-ATTR05C. " + DG1K902190
           WA_FINAL-ATTR10A       = WA_PRGEN-ATTR10A.
        READ TABLE T_V_TCAV201 INTO WA_V_TCAV201 WITH KEY ATTRV20 = WA_PRGEN-ATTR20A BINARY SEARCH.
        IF SY-SUBRC = 0.
          WA_FINAL-TEXT1   = WA_V_TCAV201-TEXT1.    "SUBID-TEXT1
        ENDIF.
        READ TABLE T_PNTPR INTO WA_PNTPR WITH KEY GUID_PR = WA_PRGEN-GUID_PR BINARY SEARCH.
        IF SY-SUBRC = 0.
           WA_FINAL-PRVSY  = WA_PNTPR-PRVSY.   "PROD NO
           WA_FINAL-GRVSY  = WA_PNTPR-GRVSY.   "LOGICAL SYS GROUP
        ENDIF.
      append wa_final to t_final.
    endloop.

  • How to change "read table ......" sentense to OO method ?

    READ TABLE lt_origin_table  into lt_target_table
                 WITH KEY user_id= lt_target_table-user_id.
    This sentense is allowed in function module but can not be written in an OO method , so what can i do ?
    Now I use 2 loops ,
    Loop at lt_origin_table ....
       loop at lt_target_table
       endloop.
    endloop.
    The result is OK , but the performance is not good enough , can any one help me ?
    Regards .

    <b>Example  :</b>   Selection of a particular line in the internal table sflight_tab and assigning it to a field symbol <sflight>. After the line has been successfully assigned, the content of a component of the line is changed in the internal table.
    PARAMETERS: p_carrid TYPE sflight-carrid,
                p_connid TYPE sflight-connid,
                p_fldate TYPE sflight-fldate.
    DATA sflight_tab TYPE SORTED TABLE OF sflight
                     WITH UNIQUE KEY carrid connid fldate.
    FIELD-SYMBOLS <sflight> TYPE sflight.
    SELECT *
           FROM sflight
           INTO TABLE sflight_tab
           WHERE carrid = p_carrid AND
                 connid = p_connid.
    IF sy-subrc = 0.
      READ TABLE sflight_tab
           WITH TABLE KEY carrid = p_carrid
                          connid = p_connid
                          fldate = p_fldate
           ASSIGNING <sflight>.
      IF sy-subrc = 0 AND
         <sflight> IS ASSIGNED.
         <sflight>-price = <sflight>-price * '0.9'.
      ENDIF.
    ENDIF.
    reward  points if it is usefull ....
    Girish

  • How can I read out metadata for captions from a Canon photo

    I have to tried to find an answer via Adobe and Google. Still not able to figure out on how to read out XMP metadata for captions out of my photos. Checking the XMP data in InDesign shows info on Camera Make, Exposure etc. But if I use metadata fields from "Caption Setup" like "Camera" the caption shows <No data from link>. Fields where the XMP field name matches (e.g. "Lens") are ok. I need following fields for the caption: Camera Make, Exposure (aperture and speed) and ISO.

    Lets keep it simple then.
    If I take my utf file generated and open and view it in notepad I can see the accented characters. But if I open it in Wordpad , the accented characetrs are corrupted.
    If I then save the file specifiying type Ascii, then the characters are written out correctly.
    What I want to do is to be able to write out the file in ascii format without having to open it in utf-mode and then having to save it in ascii.
    Ie I want the file to be opened in ascii format
    All the characters to be written in Ascii format
    But the source is still a unicode database.
    I have gone through using convert and characters get lost. In fact, at this stage, I'm not sure its possible to do What I need to do.
    Remember I am using an 8 bit character set which is why I have values above 127.
    So basically if you take the word 'Annulé'
    if I view it in wordpad it displays as
    Annulé
    But if I view it in notepad it displays as
    'Annulé' which is because notepad detects that the file has a utf-8 character in it.
    When I save it as type ascii I can then open it correctly in wordpad.
    So I basically want to open this file in Wordpad and have it display Annulé rather than the garbled characters,
    without having to go through the process of opening and saving the file as type ansi.

  • Reading photo metadata on phone?

    How can you read the metadata information for pics taken with the iphone (iOS4) while on the iphone itself? even something as simple as "date taken" would be helpful. thanks.

    You need a third party app like this:
    http://itunes.apple.com/us/app/exif-iptc-metadata-browser/id383576492?mt=8
    You can search for others.

  • How can one  read a Excel File and Upload into Table using Pl/SQL Code.

    How can one read a Excel File and Upload into Table using Pl/SQL Code.
    1. Excel File is on My PC.
    2. And I want to write a Stored Procedure or Package to do that.
    3. DataBase is on Other Server. Client-Server Environment.
    4. I am Using Toad or PlSql developer tool.

    If you would like to create a package/procedure in order to solve this problem consider using the UTL_FILE in built package, here are a few steps to get you going:
    1. Get your DBA to create directory object in oracle using the following command:
    create directory TEST_DIR as ‘directory_path’;
    Note: This directory is on the server.
    2. Grant read,write on directory directory_object_name to username;
    You can find out the directory_object_name value from dba_directories view if you are using the system user account.
    3. Logon as the user as mentioned above.
    Sample code read plain text file code, you can modify this code to suit your need (i.e. read a csv file)
    function getData(p_filename in varchar2,
    p_filepath in varchar2
    ) RETURN VARCHAR2 is
    input_file utl_file.file_type;
    --declare a buffer to read text data
    input_buffer varchar2(4000);
    begin
    --using the UTL_FILE in built package
    input_file := utl_file.fopen(p_filepath, p_filename, 'R');
    utl_file.get_line(input_file, input_buffer);
    --debug
    --dbms_output.put_line(input_buffer);
    utl_file.fclose(input_file);
    --return data
    return input_buffer;
    end;
    Hope this helps.

  • How can I read a file with ASCII Special Character into a SQL table using SSIS 2008?

    I've tried everything to read this file and am getting no where.   Help how can I read this file and load a SQL table?
    RS - AscII - 30  (Record Separator)
    GS - AscII - 29 (Group Separator)
    Thank you for your assistance - Covi
    Mark Covian

    We can use script component as source/transformation to read the text file and assign the contains to a string. Split the string by chr(30)  i.e RS and finally stored into an array or write to the output buffer of the script component.
    For example on how to use script component refer this link
    http://social.technet.microsoft.com/Forums/en-US/6ff2007d-d246-4107-b77c-624781baab38/how-to-use-substring-in-derived-column-in-ssis?forum=sqlintegrationservices
    Regards, RSingh

  • How to assigne multiple value in key of read table

    Hi gurus,
    I want read table xxxx with key field1 = ' xxx' or field1 = 'yyy'.
    how to assign multiple value as key for the same field while reading internal table.
    Regards
    sagar

    Hi ,
    You can loop the internal table like
    loop at  <table xxxx> where field1 = ' xxx' or field1 = 'yyy'
    or you can write two read statements to read the internal table in wrk area.
    read table   <table xxxx> with key field1 = ' xxx'.
    if sy-subrc <>0
    read table   <table xxxx> with key field1 = 'yyy'.
    if sy-subrc = 0
    endif.
    else.
    do your data processing.
    endif.
    Thans.

  • How do I view XMP metadata in Adobe Reader?

    How do I view XMP metadata in Adobe Reader?
    I've created a PDF which (I believe) includes XMP metadata, and I'd obviously like to check that it's been done correctly.  However it's not obvious how to view this within Adobe Reader (I'm using 11.0.04 on OS X).  Googling around, I've found an off-hand remark that Reader isn't able to do this, but this is obviously insane -- what's the point of licensing metadata if no-one can see it?  What is it I'm missing?
    Best wishes,
    Norman

    I've put a PDF at http://nxg.me.uk/temp/part1.pdf This does display/print perfectly OK in both Reader and in OS X Preview.  I presume that the /Root object (254) is inside one of the ObjStm streams (yes?), as (presumably) are the /Page streams and the reference to the /Metadata object, 52.
    Regarding scanning, Part 3 of the XMP spec, Sect 1.2 says "It is always best to use format-aware file parsing when possible. Lacking this information, applications can find XMP packets by scanning the file."  Also, in Sect. 1.2.1, "A file should be scanned byte-by-byte until a valid header is found."   Finally, ISO-32000-1 Sect. 14.3.2, Note 3, says "[The XMP spec] includes a method to embed XML data within non-XML data files in a platform-independent format that can be easily located and accessed by simple scanning rather than requiring the document file to be parsed."  So it would appear that this metadata packet _should_ be found.

  • How can i read local excel file into internal table in webdynpro for abap a

    Could someone tell me how How can i read local excel file into an internal table in webdynpro for abap application.
    thank u for your reply

    Deep,
    File manuplations...............................
    1. At the presentation level:
    ->GUI_UPLOAD
    ->GUI_DOWNLOAD
    ->CL_GUI_FRONTEND
    2. At the application server level:
    ->OPEN DATASET : open a file in the application server for reading or writing.
    ->READ DATASET : used to read from a file on the application server that has been opened for reading
    -> TRANSFER DATASET : writing data to a file.
    -> CLOSE DATASET : closes the file
    -> DELETE DATASET : delete file
    If file is on the local PC,use the function module GUI_UPLOAD to upload it into an internal table by passing the given parameters......
    call function 'GUI_UPLOAD'
    exporting
    filename = p_file
    filetype = 'ASC'
    has_field_separator = '#'
    tables
    data_tab = t_data
    p_file : excel file path.
    t_data : internal table
    <b>reward points if useful.</b>
    regards,
    Vinod Samuel.

  • How to read table fields form a table  having length of 7 characters

    HI all,
    could you please tell me how to read table fields from a table having length 7 characters, i have requirement that in my ztable i have 30 fields out of which 20 fields are location fields, i want to select 20 fields which have 7 characters length.
    please could any body suggest me on this issue.
    thanks,
    sre.

    hi,
    try like this
    create a data variable of type i as
    data: len type i.
    create internal table for 20 fields as
    data:begin of itab,
               fld 1 type .......
            end of itab.
    data:itab type itab1 occurs 0 with header line.
    loop at itab2. // original internal table which all fields.
    read table itab2 with index sy-tabix.
    len = strlen (itab2-fld).
    if len eq 7.
          move itab2 itab1.
          append itab1.
    endif.
    endloop.
    if helpful reward some points.
    with regards,
    Suresh.A

  • How will use Select-Options in Read table Concept.

    Hi All,
                  How will use Select-Options in Read table. For  example,
          Select-Options : test for bseg-prctr.
           Select * from bseg into table ITAB.
    Read table ITAB with key prctr in test.
    Last line is showing error. If any way to read ITAB as conditions given per select options.
    Thankx Advance,,,

    HI,
    you cannot use " IN " with read statement , read statement is used as:
    READ TABLE it_collect  ASSIGNING <fs_collect>
                      WITH KEY   rbpl = <fs_wkdet>-arbpl
                                 ufnr = <fs_wkdet>-aufnr.
    anyways you can use  loop at statement before read to use  " into "  statement as:
    LOOP AT it_master INTO l_master
                                           WHERE werks       = l_werks
    hope it will help you
    regards
    rahul
    Edited by: RAHUL SHARMA on Dec 30, 2008 9:14 AM

  • How to read table of accounts to read in step 2 the single accounts

    Hi,
    I want to write a litle MIS-Report with diverse FI-management-ratios.
    At the first screen (selection-screen) the user has to specify the
    table of accounts.
    So I have to know, how I can read an "table of accounts" in ABAP.
    That means the hierachy of accounts. Is there a table which
    can I read?
    Thanks a lot!

    Chart of accounts need not have any standard hierarchy. They are just grouped according to the usage. SAP treats them as sets. Any G/L account group is a set and can be found in those tables starting with SET as mentioned above.
    Chart of account is basically, an organizational unit within SAP, where any GL account is created, to be available for creation in any company code assigned to the chart of accounts.
    SKA1 is the master table of chart of accounts. Once you create a G/L account within a company code, then it becomes available in table SKB1.
    For running reports, many companies create account group which are available in SET tables.

  • How to read XMP metadata of an indd file using Actionscript

    Hi All,
    I am trying to read XMP metadata of an indd file using CS Extension Builder in Flash Builder 4.5.
    The documentation has many class like XMPmeta, XMPStruct, etc.
    I have got the currently opened document in InDesign as follows:
    var myDoc:Document = InDesign.app.activeDocument();
    And a new XMPmeta object is created as follows:
    var myXMP:XMPMeta = new XMPMeta();
    How to initialize document's xmp metadata in the XMPMeta object? Or is there any other way to get the XMP metadata of currently opened document in InDesign?

    I have found that the XMP data of an InDesign document can be retrieved in actionscript as follows:
    InDesign.app.activeDocument.metadataPreferences
    This returns the MetadataPreference object.
    But I am not able to iterate each namespace in the xmp. There isn't any XMPFile class which allows me to serialize the object to xml file so that I can iterate all elements in the XMP.
    I could not relate class like XMPMeta, XMPProp, etc. with the MetaDataPreference class. So, how to obtain the entire xmp packet from the MetadataPreference object?
    Can anyone shed light on this?

Maybe you are looking for

  • Drivers for HP laserjet 1020 printer for Macbook Pro OS 10.10.1?

    Like to install drivers in OS 10.10.1 for HP laserjet 1020 printer. When checking on App Store updates I cannot find anything. Where do I find the driver? Thank you

  • Cannot reload backup after hard drive failure

    Hard drive failed. Managed to get data backed up off it onto DVD-R. Now have new hard drive with XP loaded. Have reloaded Ipod and all software including latest updater and version of Itunes. Itunes does not recognise the disc when it is inserted, so

  • Goods reciept without any PO

    Dear Friends I received goods (MIGO) without any PO (mvt 501) in two plants of a company. The system did not ask me about the purchase group or purchase organization. Even name of the vendor was not asked. However the materials entered are maintained

  • Tables name of process order

    Hi My customer has unique requirement of report regarding process order values. I wanted the values like same as component structure according product and material group. I have searched some of the standard tables like  Aufk, Afko, resbm and tckh3.

  • IDOC Message type 'ORDCHG' - Sales Order Delete funcanility

    Dear Guru's, I have a requirement for a client where client is sending a EDI message to change & Delete a Sales order. I have mapped change option with IDOC message type 'ORDCHG' and basic message type 'ORDERS05'. Change option for the sales order is