Tuesday, July 26, 2011

query to fetch table and column name using COLNO, TBSPACEID and TABLEID (DB2)

Generally using JDBC in Java we get JDBC errors containing COLNO, TBSPACEID and TABLEID information. But most of the times we ignore these things and try to look for bugs in our JAVA code. The statement below proves to be very helpful in fast debugging of exceptions.

SELECT tabname, 
       colname 
FROM   syscat.columns 
WHERE  colno = ? 
       AND tabname = (SELECT tabname 
                      FROM   syscat.tables 
                      WHERE  tbspaceid = ? 
                             AND tableid = ?) 

No comments:

Post a Comment