//********************************************************************* // // Copyright (c) 2004-2008 by Teradata Corporation // All Rights Reserved // //********************************************************************* // // File: T20900JD.java // Header: none // Purpose: Demonstrate obtaining meta data about the client // access product. // The program will: // - Connect as user guest/please // - Obtain and display basic client access product // information // - Disconnect. // // JDBC API: java.sql.Connection, java.sql.DatabaseMetaData, // java.sql.DatabaseMetaData.getDatabaseProductName // java.sql.DatabaseMetaData.getDatabaseProductVersion // java.sql.DatabaseMetaData.getDriverName // java.sql.DatabaseMetaData.getDriverVersion // java.sql.DatabaseMetaData.getDriverMajorVersion // java.sql.DatabaseMetaData.getDriverMinorVersion // java.sql.DatabaseMetaData.getURL // java.sql.DatabaseMetaData.getUserName // // Version: Updated for Teradata V2R6 // //********************************************************************* import java.sql.*; public class T20900JD { // Name of the user able to create, drop, and manipulate tables public static String sUser = "guest"; public static String sPassword = "please"; public static void main(String args[]) throws ClassNotFoundException { // Creation of URL to be passed to the JDBC driver String url = "jdbc:teradata://whomooz/TMODE=ANSI,CHARSET=UTF8"; try { System.out.println("\n Sample T20900JD: \n"); System.out.println(" Looking for the Teradata JDBC driver... "); // Loading the Teradata JDBC driver Class.forName("com.teradata.jdbc.TeraDriver"); System.out.println(" JDBC driver loaded. \n"); // Attempting to connect to Teradata System.out.println(" Attempting to connect to Teradata via" + " the JDBC driver..."); // Creating a connection object Connection con = DriverManager.getConnection(url, sUser, sPassword); System.out.println(" User " + sUser + " connected."); System.out.println(" Connection to Teradata established. \n"); try { // Creating a DatabaseMetaData object from an active // connection. // The DatabaseMetaData class provides information about // the database as a whole. Many of the methods return // lists of information in ResultSets. Normal ResultSet // methods (getString, getInt, etc.) may be used to retrieve // the data from these ResultSets. If a given form of // metadata is not available, an SQLException is thrown. // Some methods take arguments that are String patterns. // These arguments all have names such as fooPattern. // Within a pattern String, "%" means match any substring // of zero or more characters, and "_" means match any one // character. Only metadata entries matching the search // pattern are returned. If a search pattern argument is set // to a null, it means that argument's criteria should be // dropped from the search. // An SQLException will be thrown if a driver does not // support a metadata method. For methods that return a // ResultSet, either a ResultSet (which may be empty) // is returned or an SQLException is thrown. // Please note that only a few methods are illustrated here. // For a complete list of methods, please refer to the // JDCB API and to the driver documentation for a list of // methods supported by the Teradata JDBC driver. DatabaseMetaData dbmd = con.getMetaData(); System.out.println(" DatabaseMetaData object created. \n"); // The following code will obtain information on the // database product and driver with which the user // is accessing the database. System.out.println(" DISPLAYING CLIENT ACCESS PRODUCT "+ "META DATA:\n"); // Retrieve and display the name of this database product System.out.println(" Database name : " + dbmd.getDatabaseProductName()); // Retrieve and display the version of this database product System.out.println(" Database version : " + dbmd.getDatabaseProductVersion()); // Retrieve and display the name of the jdbc driver System.out.println(" Driver name: " + dbmd.getDriverName()); // Retrieve and display the version of the jdbc driver // as a string System.out.println(" Driver version: " + dbmd.getDriverVersion()); // Retrieve and display the driver's major version number System.out.println(" Driver major version number: " + dbmd.getDriverMajorVersion()); // Retrieve and display the driver's minor version number System.out.println(" Driver minor version number: " + dbmd.getDriverMinorVersion()); // Retrieve and display the URL of the DBMS, // if it can be generated, null is returned otherwise System.out.println(" DBMS URL: " + dbmd.getURL()); // Retrieve and display the user name as it is known // to the database System.out.println(" User name as known to the database: " + dbmd.getUserName()); // Retrieve and display information on whether this database // supports certain types of ResultSet objects System.out.println(" Supports ResultSets of type" + " TYPE_FORWARD_ONLY: " + dbmd.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY)); System.out.println(" Supports ResultSets of type" + " TYPE_SCROLL_INSENSITIVE: " + dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE)); System.out.println(" Supports ResultSets of type" + " TYPE_SCROLL_SENSITIVE: " + dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE)); // Retrieve and display whether this database supports // getting multiple ResultSets from a single call to // the execute method. System.out.println(" Supports multiple ResultSets: " + dbmd.supportsMultipleResultSets()); // Retrieve and display whether this database supports // transactions System.out.println(" Supports transactions: " + dbmd.supportsTransactions()); // Retrieve and display whether this database supports // given transaction isolation levels System.out.println(" Supports transaction level" + " TRANSACTION_READ_UNCOMMITTED: " + dbmd.supportsTransactionIsolationLevel( Connection.TRANSACTION_READ_UNCOMMITTED)); System.out.println(" Supports transaction level" + " TRANSACTION_READ_COMMITTED: " + dbmd.supportsTransactionIsolationLevel( Connection.TRANSACTION_READ_COMMITTED)); System.out.println(" Supports transaction level" + " TRANSACTION_REPEATABLE_READ: " + dbmd.supportsTransactionIsolationLevel( Connection.TRANSACTION_REPEATABLE_READ)); System.out.println(" Supports transaction level" + " TRANSACTION_SERIALIZABLE: " + dbmd.supportsTransactionIsolationLevel( Connection.TRANSACTION_SERIALIZABLE)); System.out.println(" Supports transaction level" + " TRANSACTION_NONE: " + dbmd.supportsTransactionIsolationLevel( Connection.TRANSACTION_NONE)); // Retrieve and display whether this database allows // having multiple transactions open at once System.out.println(" Supports multiple transactions: " + dbmd.supportsMultipleTransactions()); } finally { // Close the connection System.out.println("\n Closing connection to Teradata..."); con.close(); System.out.println(" Connection to Teradata closed. \n"); } System.out.println(" Sample T20900JD finished. \n"); } catch (SQLException ex) { // A SQLException was generated. Catch it and display // the error information. // Note that there could be multiple error objects chained // together. System.out.println(); System.out.println("*** SQLException caught ***"); while (ex != null) { System.out.println(" Error code: " + ex.getErrorCode()); System.out.println(" SQL State: " + ex.getSQLState()); System.out.println(" Message: " + ex.getMessage()); ex.printStackTrace(); System.out.println(); ex = ex.getNextException(); } throw new IllegalStateException ("Sample failed.") ; } } // End main } // End class T20900JD