//********************************************************************* // // Copyright (c) 2004-2008 by Teradata Corporation // All Rights Reserved // //********************************************************************* // // File: T21100JD.java // Header: none // Purpose: Demonstrate retrieval and modification of connection // options // The program will: // - Connect as user guest/please // - Obtain, display, and change connection autocommit // - settings // - Disconnect. // // JDBC API: java.sql.Connection, java.sql.Connection.getAutoCommit, // java.sql.Connection.setAutoCommit // // Version: Updated for Teradata V2R6 // //********************************************************************* import java.sql.*; public class T21100JD { // 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 T21100JD: \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 { // The following code will get and set connection options. // Only getAutoCommit/setAutoCommit methods will be // demonstrated in this example. Please note that the // settings apply to and affect the current connection // only. Please refer to the supporting driver documentation // for a full list of supported methods, their implementations, // and their return values. System.out.println(" Retrieving and modifying autocommit" + " settings:\n"); // Retrieve the current/default value of the autocommit setting, // a true value is expected boolean commit = con.getAutoCommit(); System.out.println(" Default (current) autocommit value : " + commit); // Change the default autocommit value commit = false; System.out.println("\n Setting the autocommit value to : " + commit); con.setAutoCommit(commit); // Retrieve and display the new autocommit value System.out.println("\n New autocommit value : " + con.getAutoCommit()); } 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 T21100JD 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 T21100JD