Use the JDBC Driver in a Java Application - Aster Client

Teradata Aster® Client Guide

Product
Aster Client
Release Number
7.00
Published
May 2017
Language
English (United States)
Last Update
2018-04-13
dita:mapPath
hki1475000360386.ditamap
dita:ditavalPath
Generic_no_ie_no_tempfilter.ditaval
dita:id
B700-2005
lifecycle
previous
Product Category
Software
Follow these steps to integrate the Aster Database JDBC driver into your Java application:
  1. Set the CLASSPATH environment variable to include the paths of the JAR files extracted from the Aster Database JDBC driver package.
    • Use the Java -classpath flag at the command line to add the paths to the CLASSPATH environment variable. For example, if you place the JAR files in /usr/jars, then add the path like this:
      java -classpath /usr/my_program /usr/jars/

      or

    • Add the paths to the driver to the CLASSPATH environment variable. For example:
      export CLASSPATH=/usr/jars/:$CLASSPATH
  2. In your application:
    1. Import the java.sql package like this:
      import java.sql.*;
    2. Load the driver using the Class.forName() method:
      Class.forName("com.asterdata.ncluster.Driver");
    3. Define the username, password, and url (including the host, port, and database) parameters, which are needed to connect to the database. For example:
      String username = "user";
      String password = "password";
      String url    = "jdbc:ncluster://myhost:2406/database";
      For more information about the URL format, see Parameters for Connecting through JDBC.
    4. Get a Connection instance from JDBC using the DriverManager.getConnection() method:
      try
      {
         Connection conn = 
     DriverManager.getConnection(url, username, password);
      }
      catch (SQLException ex)
      {
        // could not connect
      }
      The getConnection method throws a “No driver available SQLException” exception if CLASSPATH does not contain the path for the JDBC driver, or if the parameters are incorrect.