Java Method Implementation - Analytics Database - Teradata Vantage

SQL External Routine Programming

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2023-07-11
dita:mapPath
iiv1628111441820.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
B035-1147
lifecycle
latest
Product Category
Teradata Vantage™

Here are the contents of a file called Web.java that you can compile to generate the file Web.class that you can place into a JAR file called Web.jar.

import com.teradata.fnc.*;
import java.net.*;
import java.io.*;
import java.sql.*;

public class Web {
   public static void getWebData(int ID, String url) throws SQLException
   {
      final int ClobSize = 1024*1000;
      final char[] buffer = new char[ ClobSize ];

      try {
         /* Establish default connection. */
         Connection con =
            DriverManager.getConnection( "jdbc:default:connection" );

         /* Prepare the command */
         String sql = "INSERT INTO webtab ( ? , ? )";
         PreparedStatement stmt = con.prepareStatement( sql );
         stmt.setInt( 1, ID );

         /* Get the data */
         URL urlcon = new URL( url );
         InputStreamReader data =
            new InputStreamReader(urlcon.openStream());
         int length = data.read( buffer );
         stmt.setCharacterStream(2, data, length );

         /* Insert the data. */
         stmt.execute();
         stmt.close();
      }
      catch (Exception e) {
         throw new SQLException(e.getMessage(), "38U01");
      }
   }
}