Please send questions to st10@humboldt.edu .
//
// playing with just a FEW of the Connection metatdata
// possibilities...
//
//
// NOTE: this WILL NOT WORK unless you add 
//       /home/univ/oracle/products/jdbc/lib/classes12.zip
// ...to your CLASSPATH!!!
//
// modified by: Sharon Tuttle
// last modified: 11-16-00

import java.sql.*;

public class TryConnMetaData1
{
	public static void main(String args[])
	{
		DatabaseMetaData	dbMetaData;
		PreparedStatement	myPStmt;
		Statement		myStmt;
		ResultSet		dbTableInfo;
		String			dbProdName, dbDriverName, dbURL;
		int			maxNumCols, maxNumConns;


		try
		{
                    	// load driver, set up connection
			Class.forName("oracle.jdbc.driver.OracleDriver");
			Connection con = DriverManager.getConnection
            			("jdbc:oracle:thin:@redwood:1521:student",
             			 "java", "java");

			// using the Connection con, a wealth of
			// Connection-based metadata is available;
			// this is how you get the Connection's
			// DatabaseMetaData object:
			dbMetaData = con.getMetaData();

			// this DatabaseMetaDataobject has a
			// LOT of possible methods! We'll demo
			// a few here:

			// what is the database product name involved
			// in this connection?
			dbProdName = dbMetaData.getDatabaseProductName();
			System.out.println("database product name: " +
				dbProdName);

			// what database driver are we using in this
			// connection?
			dbDriverName = dbMetaData.getDriverName();
			System.out.println("database driver name: " +
				dbDriverName);
			
			// for this connection, is user able
			// to select all tables returned by getTables()?
			if (dbMetaData.allTablesAreSelectable())
			{
				System.out.println("this connection " +
				 	"CAN select all tables it can get;");
			}
			else
			{
				System.out.println("BEWARE --- this " +
					"connection CANNOT select all " +
					"tables");
				System.out.println("   that getTables() " +
					"can get information about;");
			}		
	
			// gets a resultSet with information
			// about the tables in the database 
			// we are connected to with this
			// Connection:
			dbTableInfo = dbMetaData.getTables(
				null, 		// no catalog specified
				"JAVA",		// from user java's schema?
				"%",		// return all table names
			        null);		// all table types?

			while (dbTableInfo.next())
			{
				System.out.println("----------------");
				System.out.println("catalog: " + 
					dbTableInfo.getString(1));
				System.out.println("schema: " +
					dbTableInfo.getString(2));
				System.out.println("table name: " +
					dbTableInfo.getString(3));
				System.out.println("table type: " +
					dbTableInfo.getString(4));
				System.out.println("remarks: " +
					dbTableInfo.getString(5));
			}
			System.out.println("----------------\n\n");

			// what's the maximum number of columns in
			// a table, in the database we are connected
			// to?
			maxNumCols = dbMetaData.getMaxColumnsInTable();
			System.out.println("max number of columns allowed " +
				"in a table: " + maxNumCols);

			// how many active connections are permitted
			// at a time to this database?
			maxNumConns = dbMetaData.getMaxConnections();
			System.out.println("max number of connections " +
				"allowed: " + maxNumConns);

			// what is the URL for this database?
			dbURL = dbMetaData.getURL();
			System.out.println("URL for this database is: " +
				dbURL);

			// do not forget to close the connection
			// when done!
			con.close();
		}
		catch (Exception e)
		{
			System.out.println(e);
		}
	}
}