Teradata JDBC Driver Learning Examples





Teradata JDBC Driver Learning Examples Expand / Collapse
This documentation represents proprietary information of Teradata Corporation, and is protected by US, foreign and international intellectual property laws, including US Federal copyright law, and as such, may not be disclosed to third parties, or otherwise copied or duplicated in any form, in whole or in part, without the prior written consent of Teradata Corporation.

The purpose of this documentation is to provide examples of programs that can be used as a guide for purposes of developing JDBC applications solely for use with the Teradata Database, and is provided as an illustration of how JDBC functions operate with the Teradata Database.

This documentation, including the example programs, are provided on an "AS-IS" basis, and under no circumstances will Teradata be liable for any damages (including direct, indirect, consequential, special, punitive, incidental damages) resulting from any use even if notified of the possibility of any damages. Teradata reserves the right to change or withdraw any of the information provided in this documentation without notice.


The learning examples are split into distinct modules. Every module consists of one or more examples within a general theme, exemplifying a specific aspect of the JDBC driver. All examples are thoroughly documented to explain newly encountered features as they are used.

The modules are as follows:

ModuleDescription
0Sets up the environment, creating necessary tables and indexes
1Shows how to obtain result set meta data for a SQL statement
2Illustrates performing insertions into the sample tables
3Illustrates performing selections from the sample tables
4Illustrates performing updates to the sample tables
5Illustrates performing deletions from the sample tables
6Illustrates creation and execution of stored procedures
7Illustrates execution of multi-statement requests
8Illustrates creation and execution of macros
9Illustrates obtaining various information about the database
10Illustrates searching for specific information about the database
11Illustrates obtaining and modifying client access product options
12Illustrates using the J2SE 5.0 (JDK 1.5) JdbcRowSetImpl
13Illustrates using DataSources
14Illustrates creation and execution of User-Defined Functions (UDFs)
15Illustrates Teradata-specific data type conversions
16Illustrates the use of JDBC Escape Syntax
18Illustrates the use of JDBC Updatable Result Set
19Illustrates the use of SET QUERY_BAND statement
99Cleans up the environment

The table below shows the example breakdown into modules, with the respective example file name and description.

ModuleFile Name Program Description
0T20000JD.javaSet up the example environment (users, databases, tables, indexes)
0T20001JD.javaSet up the example environment (users, databases, tables, indexes)
0T20002JD.javaSet up the example environment (users, databases, tables, indexes)
0T20003JD.javaSet up the example environment (users, databases, global temporary tables, indexes)
1T20100JD.javaExecute a SQL statement and obtain any result set column meta data
1T20101JD.javaExecute a SQL statement and obtain any result set column meta data
2T20200JD.javaInsert non LOB columns into a row in a table, without using parameter markers
2T20201JD.javaInsert non LOB columns into a row in a table, using parameter markers
2T20202JD.javaInsert LOB columns into a row in a table, without using parameter markers
2T20203JD.javaInsert LOB columns into a row in a table, using parameter markers
2T20204JD.javaInsert data into a table and display the generated keys
2T20205JD.javaInsert data into a table using FastLoad with auto-commit true
2T20206JD.javaInsert data into a table using FastLoad with auto-commit false
2T20207JD.javaInsert data into a table using FastLoad with auto-commit false and verify FastLoad sessions
3T20300JD.javaSelect non-LOB columns from a specific row, from a table, without using parameter markers for the predicate values. Also obtain column meta data.
3T20301JD.javaSelect non-LOB columns from a specific row, from a table, using parameter markers for the predicate values. Also obtain column meta data.
3T20302JD.javaSelect LOB columns from a specific row, from a table, without using parameter markers for the predicate values. Also obtain column meta data.
3T20303JD.javaSelect LOB columns from a specific row, from a table, using parameter markers for the predicate values. Also obtain column meta data.
3T20304JD.javaObtain result set metadata prior to executing the prepared statement
3T20305JD.javaObtain parameter metadata prior to executing the prepared statement
3T20306JD.javaSelect data from a table using FastExport without parameter marker
3T20307JD.javaSelect data from a table using FastExport with parameter marker
3T20308JD.javaSelect data from a table using FastExport with parameter marker and verify FastExport sessions
4T20400JD.javaUpdate a non-LOB column from a specific row, from a table, without using parameter markers for the update and predicate values
4T20401JD.javaUpdate a non-LOB column from a specific row, from a table, using parameter markers for the update and predicate values
4T20402JD.javaUpdate a LOB column from a specific row, from a table, without using parameter markers for the update and predicate values
4T20403JD.javaUpdate a LOB column from a specific row, from a table, using parameter markers for the update and predicate values
4T20404JD.javaUpdate a LOB column from a specific row, from a table, using the set methods for the update and predicate values
5T20500JD.javaDelete a specific row, from a table, without using parameter markers for predicate values
5T20501JD.javaDelete a specific row, from a table, using parameter markers for the predicate values
6T20600JD.javaCreate (if allowed) and execute a stored procedure and obtain its results (no LOB parameters)
6T20601JD.javaCreate (if allowed) and execute a stored procedure and obtain its results (LOB parameters)
6T20602JD.javaCreate (if allowed) and execute an external stored procedure and obtain its results
6T20603JD.javaInstall (if allowed) a jar file for sample Java Stored Procedures
6T20604JD.javaCreate (if allowed) and execute a Java Stored Procedure (no LOB parameters)
6T20605JD.javaCreate (if allowed) and execute a Java Stored Procedure (with a LOB parameter)
6T20606JD.javaCreate (if allowed) and execute a SQL stored procedure and retrieve its dynamic result set
6T20607JD.javaCreate (if allowed) and execute a Java stored procedure and retrieve its dynamic result set
6T20608JD.javaCreate (if allowed) and execute a Java stored procedure and retrieve its multiple dynamic result sets
7T20700JD.javaExecute a multi-statement request that contains only non-SELECT statements, and obtain the results
7T20701JD.javaExecute a multi-statement request that contains only SELECT statements, and obtain the results
7T20702JD.javaExecute a multi-statement request that contains both SELECT and non-SELECT statements, and obtain the results
7T20703JD.javaExecute a multi-statement INSERT request and display the generated keys
7T20704JD.javaExecute a multi-statement batch INSERT request and display the generated keys
7T20705JD.javaExecute a multi-statement request and make all results available simultaneously
8T20800JD.javaExecute a macro that contains only non-SELECT statements, and obtain the results
8T20801JD.javaExecute a macro that contains only SELECT statements, and obtain the results.
8T20802JD.javaExecute a macro that contains both SELECT and non-SELECT statements, and obtain the results.
9T20900JD.javaObtain meta data about the client access product
9T20901JD.javaObtain a list of reserved words
9T20902JD.javaObtain a list of all supported SQL data types
9T20903JD.javaObtain a list of all table types
9T20904JD.javaObtain table index meta data
9T20905JD.javaObtain the names of all databases
9T20906JD.javaObtain the names of all tables in all databases
9T20907JD.javaObtain the names of all columns in all tables in all databases
9T20908JD.javaObtain the names of all procedures in all databases
9T20909JD.javaObtain the names of all procedure columns in all databases
9T20910JD.javaObtain a list of primary key columns for a specific table
9T20911JD.javaObtain an optimal set of columns that uniquely identifies a row for a specific table
9T20912JD.javaObtain a list of the user-defined types (UDTs) defined in a particular schema
9T20913JD.javaObtain a description of the given attribute of the given type for a user-defined type (UDT) that is available in the given schema and catalog
9T20914JD.javaDemonstrate use of SET SESSION RATE and MONITOR SESSION.
10T21000JD.javaSearch for a specific table type
10T21001JD.javaSearch for specific databases by name
10T21002JD.javaSearch for specific databases by wildcard characters
10T21003JD.javaSearch for specific tables by name (a table here can actually any object that Teradata thinks of as in the "TVM" category, such as stored procedures and UDFs)
10T21004JD.javaSearch for specific tables by wildcard characters
10T21005JD.javaSearch for specific columns by name
10T21006JD.javaSearch for specific columns by wildcard characters
10T21007JD.javaSearch for specific procedures by name
10T21008JD.javaSearch for specific procedures by name by wildcard characters
10T21009JD.javaSearch for specific procedure columns by name
10T21010JD.javaSearch for specific procedure columns by wildcard characters
11T21100JD.javaGetting and setting connection options
11T21101JD.javaGetting and setting statement options
11T21102JD.javaUse transaction isolation level TRANSACTION_READ_UNCOMMITTED
11T21104JD.javaUse URL/DataSource Parameter NEW_PASSWORD to automatically handle Database Password expiration
11T21105JD.javaUse URL/DataSource Parameter USEXVIEWS
12T21200JD.javaCreate and use JdbcRowSetImpl, given a connection URL, user, and password
12T21201JD.javaCreate and use JdbcRowSetImpl, given an existing connection
12T21202JD.javaCreate and use JdbcRowSetImpl, given an existing result set
13T21300JD.javaProgrammatically create a DataSource (see note below)
13T21301JD.javaProgrammatically create a ConnectionPoolDataSource (see note below)
13T21302JD.javaObtain a connection from a DataSource (see note below)
14T21400JD.javaCreate and execute a User-Defined Function (UDF)
14T21401JD.javaInstall a jar file for sample Java User Defined Function (JUDF)
14T21402JD.javaCreate and execute a Java User Defined Function (JUDF)
15T21500JD.javaPerform Teradata-specific data type conversions
16T21600JD.javaUse JDBC Escape Syntax
18T21800JD.javaUse JDBC Updatable Result Set from a non-prepared Statement
18T21801JD.javaUse JDBC Updatable Result Set from a PreparedStatement
18T21802JD.javaUse JDBC Updatable Result Set from a CallableStatement
19T21900JD.javaUse SET QUERY_BAND statement
19T21901JD.javaUse SET QUERY_BAND statement with PROXYUSER
99T29900JD.javaClean up the example environment (user, database, tables, indexes)

A sample application to test a connection is also provided, sample1.java.


Use the following procedure to run the Teradata JDBC Driver Learning Examples:

  1. Download a supported JDK to your development platform.

  2. Download and copy samples.jar, terajdbc4.jar, and tdgssconfig.jar to your development platform. Note: tdgssjava.jar is also required for TTU 8.2/Teradata JDBC Driver 3.4 or earlier releases. The commands below assume that all the files are copied to the same directory on your development platform.

  3. Go to the directory where samples.jar is located and unjar the sample applications:

    jar xvf samples.jar

  4. Modify the sample application sample1.java with your Teradata Database information.

    You need to change the following:

    • Name of the Teradata Database.
    • Userid and password for the Teradata Database.

  5. Compile the modified sample application by entering the following:

    javac sample1.java

  6. Run the application on Windows by entering the following:

    java -classpath .;terajdbc4.jar;tdgssconfig.jar sample1

    Or run the application on UNIX by entering the following:

    java -classpath .:terajdbc4.jar:tdgssconfig.jar sample1

    With TTU 8.2/Teradata JDBC Driver 3.4 or earlier releases, run the application on Windows by entering the following:
    java -classpath .;terajdbc4.jar;tdgssjava.jar;tdgssconfig.jar sample1

    With TTU 8.2/Teradata JDBC Driver 3.4 or earlier releases, run the application on UNIX by entering the following:
    java -classpath .:terajdbc4.jar:tdgssjava.jar:tdgssconfig.jar sample1

Note: The "." entry, representing the current directory, on the classpath in the commands above is what enables Java to locate the sample1.class file.

Repeat steps 4, 5, and 6 for each of the other Learning Example programs.

Note: The Java Stored Procedure samples in Module 6 must be compiled and placed into the SampleJXSP.jar file before they can be installed on the Teradata Database. The steps listed below assume that you have already unjarred the contents of samples.jar

  1. Compile the Java Stored Procedure samples by entering the following:

    javac -d . BookInfo.java DeptJobInfo.java EmpInfo.java

  2. Jar the Java Stored Procedure samples by entering the following:

    jar cvf SampleJXSP.jar com/teradata/sample/BookInfo.class com/teradata/sample/DeptJobInfo.class com/teradata/sample/EmpInfo.class

  3. Modify the sample application T20603JD.java with your Teradata Database information.

    You need to change the following:

    • Name of the Teradata Database.
    • Userid and password for the Teradata Database.

  4. Compile the modified sample application by entering the following:

    javac T20603JD.java

  5. Run the application on Windows by entering the following:

    java -classpath .;terajdbc4.jar;tdgssconfig.jar T20603JD

    Or run the application on UNIX by entering the following:

    java -classpath .:terajdbc4.jar:tdgssconfig.jar T20603JD

    As shown above, tdgssjava.jar must also be listed on the classpath for TTU 8.2/Teradata JDBC Driver 3.4 or earlier releases.

Note:The Java User Defined Function sample in module 14 must be compiled and placed into the SampleJavaUDF.jar file before they are installed on the Teradata database. The steps listed below assume that you have already unjarred the contents of samples.jar

  1. Compile the Java User Defined Function sample by entering the following:

    javac -d . JavaUDFClass.java

  2. Jar the Java User Defined Function sample by entering the following:

    jar cvf SampleJavaUDF.jar com/teradata/sample/JavaUDFClass.class

  3. Modify the sample application T21401JD.java with your Teradata Database information.

    You need to change the following:

    • Name of the Teradata Database.
    • Userid and password for the Teradata Database.

  4. Compile the modified sample application by entering the following:

    javac T21401JD.java

  5. Run the application on Windows by entering the following:

    java -classpath .;terajdbc4.jar;tdgssconfig.jar T21401JD

    Or run the application on UNIX by entering the following:

    java -classpath .:terajdbc4.jar:tdgssconfig.jar T21401JD

    As shown above, tdgssjava.jar must also be listed on the classpath for TTU 8.2/Teradata JDBC Driver 3.4 or earlier releases.

Note: The Module 13 DataSource Learning Examples require the com.sun.jndi.fscontext.RefFSContextFactory class, which is included in the fscontext.jar file of the J2EE SDK. In order to run the Module 13 DataSource Learning Examples, you need to download and install the J2EE SDK from Sun and include fscontext.jar and providerutil.jar on your classpath.

  Download Files 
samples.jar ( 269.84 KB )




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