Examples - Advanced SQL Engine - Teradata Database

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-27
dita:mapPath
rin1593638965306.ditamap
dita:ditavalPath
rin1593638965306.ditaval
dita:id
B035-1147
lifecycle
previous
Product Category
Teradata Vantageā„¢

Example: Establishing a Default Connection to Vantage

public class region {

   public static void getRegion(String[] data) throws SQLException
   {
      String sql = "SELECT Region FROM Sales WHERE ID = ";
      try {
         /* Establish default connection. */
         Connection con = 
            DriverManager.getConnection( "jdbc:default:connection " ); 
         /* Execute the statement */
         Statement stmt = con.createStatement();
         ResultSet rs = stmt.executeQuery( sql + data[0] );
         rs.next();
         data[0] = rs.getString("Region");
         stmt.close();
      }
      catch (Exception e) {
         throw new SQLException(e.getMessage(),"38U01");
      }
   }

   ...

}

Example: External Stored Procedure That Reads SQL Data

The following statement specifies the READS SQL DATA data access clause because the getRegion() method that implements the GetRegion external stored procedure (see dsq1593709706977.html#fuh1472240849902__exestabdefaultconn) executes a SELECT statement.

CREATE PROCEDURE GetRegion(INOUT Str VARCHAR(120))
   LANGUAGE JAVA
   READS SQL DATA
   PARAMETER STYLE JAVA
   EXTERNAL NAME 'JarXSP:region.getRegion';