pbergin
09-26-02, 11:41
| Sorry for the DB2/Java cross post, I was not sure who could best answer my question) Hi I am having a problem getting db tables from a DB2 mainframe over ODBC (I have to use ODBC). I connect with the below code and write out the table and column names rather than getting the correct table and column names for this schema (eg Customer.name, Customer-Age) I get the below information. V53_BMCLGRNX.LGRDBID - CHARacter V53_BMCLGRNX.LGRPSID - CHARacter V53_BMCLGRNX.LGRUCDT - CHARacter V53_BMCLGRNX.LGRUCTM - CHARacter V53_BMCLGRNX.LGRSRBA - CHARacter V53_BMCLGRNX.LGRSPBA - CHARacter V53_BMCLGRNX.LGRPART - SMALLINT V53_BMCLGRNX.LGRSLRSN - CHARacter V53_BMCLGRNX.LGRELRSN - CHARacter V53_BMCLGRNX.LGRMEMBER - CHARacter I get loads of these tables. Can some one tell me what these tables are, should I asking for different table types? String[] types = {"TABLE"}; tablesDbMetaData = db.getTables(null,null,null,types); Hope you can help me out. Paul The java code import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.DatabaseMetaData; import java.util.Vector; public class Main { public static void main(String[] args) { ResultSet columnNames = null; ResultSet tablesDbMetaData = null; Connection con = null; try { //Load the jdbc driver if (args.length != 4) {usage(); System.exit(0);} String[] types = {"TABLE"}; String url = args[0]; String userName = args[1]; String password = args[2]; String driverName = args[3]; Vector tableNames = new Vector(); String tableName = ""; Class.forName(driverName); con = DriverManager.getConnection(url, userName, password); System.out.println("Connected."); DatabaseMetaData db = con.getMetaData(); System.out.println("Got meta data."); tablesDbMetaData = db.getTables(null,null,null,types); try{ while(tablesDbMetaData.next()) { tableName = tablesDbMetaData.getString("TABLE_NAME"); tableNames.add(tableName); } } catch(Exception ex) { System.out.println(ex.toString()); } for(int t=0; t<tableNames.size(); t++) { columnNames = db.getColumns(null, null, (String)tableNames.elementAt(t), null); int i = -1; while(columnNames.next()) { i = columnNames.getRow(); System.out.print(i); System.out.print(". "); System.out.print(columnNames.getString("TABLE_NAME") + "."); System.out.print(columnNames.getString("COLUMN_NAME")); System.out.print(" - "); System.out.println(columnNames.getString("TYPE_NAME")); } if (i < 0) System.out.println("No columns found for table " + tableName); } } catch (Exception ex) { ex.printStackTrace(); } finally { try {columnNames.close();} catch (Exception ex) {ex.printStackTrace();} try {con.close();} catch (Exception ex) {ex.printStackTrace();} } } private static void usage() { System.out.println("usage: Main url userName password driverName tableName"); } } |