mallett76 has asked for the wisdom of the Perl Monks concerning the following question:
Hello, the below code works in Java, but it is not working using Inline Java, was wondering why
Below is the code. Any ideas or suggestions would be appreciated
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 = "xxxxxx"; public static void main(String args[]) throws ClassNotFoundException { // Creation of URL to be passed to the JDBC driver //commented out on 12/19/23 String url = "jdbc:teradata://whom +ooz/TMODE=ANSI,CHARSET=UTF8"; //commented out on 12/21/23 String url = "jdbc:teradata:// +172.28.130.20/LOGMECH=LDAP"; String url = "jdbc:teradata://000.00.000.00/TMODE=TERA,DBS_PORT=1025, +CHARSET=UTF8,LOGMECH=LDAP,SSLMODE=ALLOW"; // Statements used in table creation 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))"; // Statements used in index creation. Both unique and non-uniq +ue indexes // will be created. Please note that these may not result in o +ptimal // performance. 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. +.. "); // Loading the Teradata JDBC driver Class.forName("com.teradata.jdbc.TeraDriver"); System.out.println(" JDBC driver loaded. \n"); // Attempting to connect to Teradata System.out.println(" Attempting to connect to Teradata via +" + " the JDBC driver..."); // Creating a Connection object. A Connection represents a + session // with a specific database. Within the context of a Conne +ction, // SQL statements are executed and results are returned. // Creating a database connection with the given database +URL, // user name, and password Connection con = DriverManager.getConnection(url, sUser, s +Password); System.out.println(" User " + sUser + " connected."); System.out.println(" Connection to Teradata established. \ +n"); try { // Creating a statement object from an active connecti +on. // A Statement object is used for executing a static S +QL // statement and obtaining the results produced by the + statement. // Statement.executeUpdate method is used to execute a + SQL // INSERT, UPDATE or DELETE statement. SQL statements +that // return nothing, such as DDL statements, can be exec +uted // as well. The method will return the row count for I +NSERT, // UPDATE, or DELETE, or zero for statements that retu +rn nothing. Statement stmt = con.createStatement(); System.out.println(" Statement object created. \n"); try { // Cleanup procedure: // If the sample table already exists, drop it. // Please note that the "no table present" excepti +on // will be raised if and only if no table "employe +e" already // exists, as during the very first execution of t +his // example. If a user wants to replicate this erro +r multiple // times, the table will have to be manually remov +ed before // running this example again in order for the err +or to // occur. 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) { // If the table did not exist, no drop is requ +ired. // Ignore the raised "no table present" except +ion by // printing out the error message and swallowi +ng the // exception. If multiple exceptions are chain +ed // together, display information on all of the +m. // The following code will demonstrate some of + the // methods available for retrieving informatio +n about // SQLExceptions, some inherited from the Thro +wable // class. Please refer to JDBC API for other // method descriptions. while (ex != null) { // Display a short description of the exce +ption. // Returns information generated by the to +String() // method: a concatenation of three string +s: // - Name of the actual class of this obje +ct // - ": " (a colon and a space) // - Result of the getMessage() method for + this // object System.out.println("\n Drop table exceptio +n " + "ignored: " + ex); // Display vendor-specific exception code +for this // SQLException object. System.out.println(" Error code: " + ex.getErrorCode()); // Display the SQLState for this SQLExcept +ion object. System.out.println(" SQL State: " + ex.getSQLState()); // Display the detail message string, if a +ny. System.out.println(" Message: " + ex.getMessage()); // Display the localized description of th +is // exception, if any. Default implementati +on returns // the same result as getMessage(). System.out.println(" Localized Message: " + ex.getLocalizedMessag +e()); // Print this error and its backtrace to t +he // standard error stream. System.out.println(" Stack Trace: "); ex.printStackTrace(); // Retrieve the exception chained to this // SQLException object, if any. ex = ex.getNextException(); } System.out.println(" Table could not be droppe +d." + " Execution will continue.. +.\n"); } // Create the sample table System.out.println(" Creating table: " + sCreateTb +l); stmt.executeUpdate(sCreateTbl); System.out.println(" Sample table created. \n"); // Create table indexes System.out.println(" Creating table indexes: " + sCreateIdx + " " + sCreateIdx +2); stmt.executeUpdate(sCreateIdx); stmt.executeUpdate(sCreateIdx2); System.out.println(" Table indexes created."); } finally { // Close the statement stmt.close(); System.out.println("\n Statement object closed. \n +"); } } finally { // Close the connection 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) { // A SQLException was generated. Catch it and display // the error information. // Note that there could be multiple error objects chained // together. 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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Inline Java not working
by stevieb (Canon) on Dec 28, 2023 at 19:55 UTC | |
by mallett76 (Beadle) on Jan 17, 2024 at 16:39 UTC | |
by afoken (Chancellor) on Jan 17, 2024 at 19:19 UTC | |
by mallett76 (Beadle) on Feb 17, 2024 at 14:09 UTC | |
by mallett76 (Beadle) on Feb 15, 2024 at 15:41 UTC | |
by mallett76 (Beadle) on Jan 04, 2024 at 20:50 UTC | |
by mallett76 (Beadle) on Feb 17, 2024 at 14:11 UTC | |
by mallett76 (Beadle) on Jan 05, 2024 at 16:39 UTC | |
|
Re: Inline Java not working
by InfiniteSilence (Curate) on Dec 29, 2023 at 03:41 UTC | |
by mallett76 (Beadle) on Jan 03, 2024 at 17:42 UTC | |
|
Re: Inline Java not working
by karlgoethebier (Abbot) on Dec 30, 2023 at 05:58 UTC | |
by jdporter (Paladin) on Jan 02, 2024 at 20:30 UTC | |
by karlgoethebier (Abbot) on Jan 02, 2024 at 22:09 UTC | |
by jdporter (Paladin) on Jan 02, 2024 at 22:49 UTC | |
by ikegami (Patriarch) on Jan 02, 2024 at 22:43 UTC | |
|
Re: Inline Java not working
by Bod (Parson) on Jan 02, 2024 at 23:10 UTC | |
by mallett76 (Beadle) on Jan 03, 2024 at 17:39 UTC | |
by Bod (Parson) on Jan 04, 2024 at 22:10 UTC | |
|
Re: Inline Java not working
by bliako (Abbot) on Jan 03, 2024 at 11:54 UTC | |
by hippo (Archbishop) on Jan 03, 2024 at 13:58 UTC | |
by bliako (Abbot) on Jan 03, 2024 at 14:46 UTC |