/* This is a sample program for simple DatabaseMetaData function.
 * Replace mylogin & mypassword by your login & password respectively.
 */ 

import java.sql.*;

public class databaseMetaData {
	public static void main( String[] args ) throws SQLException {
		Connection con = null;
		DatabaseMetaData dbmd = null;
		ResultSet rs = null;
		ResultSetMetaData rsmd = null;

		try {
			DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver());
			/* Please substitute mylogin, mypassword by your login 
			 * and password.
			 */
			con = DriverManager.getConnection( "jdbc:oracle:thin:@10.105.1.30:1521:oradb", "dbis","dbis");

			dbmd = con.getMetaData();

			/* Following function returns all the tables in the
			 * database.
			 * The second argument to the function is schema name
			 * which should be your login name in capital letters
			 * e.g. with second argument as DBIS, the function 
			 * returns all the tables for that user.
			 */
			rs = dbmd.getTables( null, "DBIS", "%", null );

			rsmd = rs.getMetaData();

			System.out.println( "-------------------------------------------------------------------------------" );
			for( int i = 1; i <= rsmd.getColumnCount(); i++ ) {
				System.out.print( rsmd.getColumnName(i)  + "\t" );
			}

			System.out.print( "\n" );
			System.out.println( "-------------------------------------------------------------------------------" );

			while (rs.next()) {
				for( int i = 1; i <= rsmd.getColumnCount(); i++ ) {
					System.out.print( rs.getString(i) + "\t\t" );
				}
				System.out.print( "\n" );
			}
		} catch(SQLException sqle){
			System.out.println("Exception " + sqle);
		}
	}
}
