Posted By

balbuenac on 09/13/08


Tagged

tables jdbc metadata


Versions (?)

Get Tables Lista using JDBC


 / Published in: Java
 

URL: http://www.herongyang.com/jdbc/JDBC-ODBC-Flat-File-List-Tables.html

  1. /**
  2.  * OdbcFlatListTables.java
  3.  * Copyright (c) 2007 by Dr. Herong Yang. All rights reserved.
  4.  */
  5. import java.sql.*;
  6. public class OdbcFlatListTables {
  7. public static void main(String [] args) {
  8. Connection con = null;
  9. try {
  10. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  11. con = DriverManager.getConnection("jdbc:odbc:HY_FLAT");
  12.  
  13. DatabaseMetaData meta = con.getMetaData();
  14. ResultSet res = meta.getTables(null, null, null,
  15. new String[] {"TABLE"});
  16. System.out.println("List of tables: ");
  17. while (res.next()) {
  18. System.out.println(
  19. " "+res.getString("TABLE_CAT")
  20. + ", "+res.getString("TABLE_SCHEM")
  21. + ", "+res.getString("TABLE_NAME")
  22. + ", "+res.getString("TABLE_TYPE")
  23. + ", "+res.getString("REMARKS"));
  24. }
  25. res.close();
  26.  
  27. con.close();
  28. } catch (Exception e) {
  29. System.err.println("Exception: "+e.getMessage());
  30. }
  31. }
  32. }

Report this snippet  

You need to login to post a comment.