in reply to Re: Inline Java not working
in thread Inline Java not working
I removed the comments to make it easier to read.
Here is the updated code.
use Inline Java => <<'END_OF_JAVA_CODE' ; import java.sql.*; public class T20000JD { // Name of the user able to create, drop, and manipulate tables public static String sUser = "XXXXX"; public static String sPassword = "XXXXX"; public static void main(String args[]) throws ClassNotFoundException { String url = "jdbc:teradata://172.28.130.20/TMODE=TERA,DBS_PORT=1025, +CHARSET=UTF8,LOGMECH=LDAP,SSLMODE=ALLOW"; String sDropTbl = "DROP TABLE NED_COLL_TABLES.T_PM_TEST_TMP"; String sCreateTbl = "CREATE TABLE NED_COLL_TABLES.T_PM_TEST_TM +P (empID INTEGER NOT NULL, " + "empName VARCHAR(30) NOT NULL, empDept VARCHAR(50) NOT NUL +L, " + "empJob VARCHAR(300), PRIMARY KEY(empID))"; String sCreateIdx = "CREATE INDEX (empName) ON employee"; String sCreateIdx2 = "CREATE UNIQUE INDEX (empName, empDept) O +N employee"; try { System.out.println("\n Sample T20000JD: \n"); System.out.println(" Looking for the Teradata JDBC driver. +.. "); Class.forName("com.teradata.jdbc.TeraDriver"); System.out.println(" JDBC driver loaded. \n"); System.out.println(" Attempting to connect to Teradata via +" + " the JDBC driver..."); Connection con = DriverManager.getConnection(url, sUser, s +Password); System.out.println(" User " + sUser + " connected."); System.out.println(" Connection to Teradata established. \ +n"); try { Statement stmt = con.createStatement(); System.out.println(" Statement object created. \n"); try { try { System.out.println(" Dropping table if present +: " + sDropTbl); // Executing the drop table command stmt.executeUpdate(sDropTbl); System.out.println(" Table dropped.\n"); } catch (SQLException ex) { while (ex != null) { System.out.println("\n Drop table exceptio +n " + "ignored: " + ex); System.out.println(" Error code: " + ex.getErrorCode()); System.out.println(" SQL State: " + ex.getSQLState()); System.out.println(" Message: " + ex.getMessage()); System.out.println(" Localized Message: " + ex.getLocalizedMessag +e()); System.out.println(" Stack Trace: "); ex.printStackTrace(); ex = ex.getNextException(); } System.out.println(" Table could not be droppe +d." + " Execution will continue.. +.\n"); } System.out.println(" Creating table: " + sCreateTb +l); stmt.executeUpdate(sCreateTbl); System.out.println(" Sample table created. \n"); System.out.println(" Creating table indexes: " + sCreateIdx + " " + sCreateIdx +2); stmt.executeUpdate(sCreateIdx); stmt.executeUpdate(sCreateIdx2); System.out.println(" Table indexes created."); } finally { stmt.close(); System.out.println("\n Statement object closed. \n +"); } } finally { System.out.println(" Closing connection to Teradata... +"); con.close(); System.out.println(" Connection to Teradata closed. \n +"); } System.out.println(" Sample T20000JD finished. \n"); } catch (SQLException ex) { System.out.println(); System.out.println("*** SQLException caught ***"); while (ex != null) { System.out.println(" Error code: " + ex.getErrorCode() +); System.out.println(" SQL State: " + ex.getSQLState()); System.out.println(" Message: " + ex.getMessage()); ex.printStackTrace(); System.out.println(); ex = ex.getNextException(); } throw new IllegalStateException ("Sample failed.") ; } } // End main } // End class T20000JD END_OF_JAVA_CODE
|
|---|