sample1.java





sample1.java Expand / Collapse
//************************************************************************************
//
//                 Copyright (c) 2004-2008 by Teradata Corporation
//                         All Rights Reserved
//
//                   TERADATA CORPORATION CONFIDENTIAL AND TRADE SECRET
//
//************************************************************************************
//
//  File:       sample1.java
//  Purpose:    This sample application will:
//               - log on
//               - log off
//
//************************************************************************************

import java.sql.*;

public class sample1
{
    public static void main (String [] args)
    throws ClassNotFoundException
    {
        // Teradata Type 4 JDBC Driver
        String url = "jdbc:teradata://whomooz/TMODE=ANSI,CHARSET=UTF8";

        try
        {
            // Load the Teradata Driver
            Class.forName ("com.teradata.jdbc.TeraDriver");

            // Connect to the Teradata database specified in the URL
            // and submit userid and password.
            System.out.println("Connecting to " + url);
            Connection con = DriverManager.getConnection (url, "guest", "please");
            System.out.println("Established successful connection");

            con.close();
            System.out.println("Disconnected");
        }
        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.") ;
        }
    }
}



Questions or Feedback
Contact Us
 
Related Resources
Teradata Developer Exchange
Teradata Discussion Forums
White Papers
Teradata Support Services
Teradata User Groups


Find more downloads (including early access and unsupported releases) on Teradata Developer Exchange.
Company Newsroom Site Help Site Map Privacy/Legal Contact Us