//********************************************************************* // // Copyright (c) 2004-2008 by Teradata Corporation // All Rights Reserved // //********************************************************************* // // File: T21008JD.java // Header: none // Purpose: Demonstrate searching for a specific procedure using // wildcard characters // The program will: // - Connect as user guest/please // - Obtain and display names of all procedures // matching a specified name pattern containing // wildcard characters // - Disconnect. // // JDBC API: java.sql.Connection, java.sql.DatabaseMetaData, // java.sql.DatabaseMetaData.getProcedures // // Version: Updated for Teradata V2R6 // //********************************************************************* import java.sql.*; public class T21008JD { // 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"; // Name used for procedure search, using wildcard characters String procWildName = "get%Info"; try { System.out.println("\n Sample T21008JD: \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. DatabaseMetaData dbmd = con.getMetaData(); System.out.println(" DatabaseMetaData object created. \n"); // The following code obtains the names of all procedures // in all databases matching a specific name pattern // Use getProcedures to generate a result set of procedures ResultSet rs = dbmd.getProcedures(null, null, procWildName); // Display the procedure names. System.out.println(" DISPLAYING ALL PROCEDURES MATCHING \"" + procWildName + "\" :\n"); System.out.println(" Database Name : Procedure Name : " + "Procedure Type"); System.out.println(" ---------------------------------" + "--------------"); while(rs.next()) { System.out.println(" " + rs.getString("PROCEDURE_SCHEM") + " : " + rs.getString("PROCEDURE_NAME") + " : " + rs.getString("PROCEDURE_TYPE")); } } 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 T21008JD 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 T21008JD