Java Method Implementation - Advanced SQL Engine - Teradata Database

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-24
dita:mapPath
qwr1571437338192.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1147
lifecycle
previous
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");
      }
   }
}