17.10 - Examples - Advanced SQL Engine - Teradata Database

Teradata Vantageā„¢ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1147-171K
Language
English (United States)

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';