in reply to Re: Inline Java not working
in thread Inline Java not working

I have updated my code. Unfortunately, I have not been able to get this program to run. However, at least I now have an error message

I am receiving the following error message:

  main::java::lang::ClassNotFoundException=HASH(0x33f4400)

Here is my updated code

use strict; use warnings; use Inline Java => <<'END'; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; public class TeradataTableCreator { public static void createTable(String jdbcUrl, String username, Stri +ng password) throws Exception { // Load Teradata JDBC driver Class.forName("com.teradata.jdbc.TeraDriver"); // Establish the connection Connection connection = DriverManager.getConnection(jdbcUrl, usern +ame, password); // Create a Statement Statement statement = connection.createStatement(); // Execute the SQL statement to create a sample table String createTableSQL = "CREATE TABLE SampleTable (ID INT, Name VA +RCHAR(255))"; statement.executeUpdate(createTableSQL); // Close resources statement.close(); connection.close(); } } END # Specify your Teradata connection details my $jdbcUrl = "jdbc:teradata://000.00.000.00/TMODE=TERA,DBS_PORT=1025, +CHARSET=UTF8,LOGMECH=LDAP,SSLMODE=ALLOW"; my $username = "XXXXX"; my $password = "XXXXXX"; # Call the Java method to create the table TeradataTableCreator->createTable($jdbcUrl, $username, $password);

Replies are listed 'Best First'.
Re^3: Inline Java not working
by afoken (Chancellor) on Jan 17, 2024 at 19:19 UTC

      Yahoo! - I solved the problem - wasn't easy, but I did it. I'll share my code in case anyone else has the issue. The big item was I had to point to my class path jar file to point to terajdbc4.jar

      use strict; use warnings; use Inline Java => <<'END' => CLASSPATH => 'C:/jars/terajdbc4.jar'; import java.sql.Connection; import java.util.*; import java.sql.DriverManager; import java.sql.SQLException; import java.io.PrintWriter; import java.sql.*; public class TeradataConnectionTest { public static void testConnection(String jdbcUrl, String username, Str +ing password) { try { System.out.println("Test up to part 1"); //e.printStackTrace(); //DriverManager.registerDriver(new com.teradata.jdbc.TeraDriver()); //DriverManager.registerDriver(new com.teradata.jdbc.TeraDriver()); Di +d not work Class.forName("com.teradata.jdbc.TeraDriver"); //Did not work // Class.forName("com.ncr.teradata.TeraDriver"); Did not work Connection connectionA = DriverManager.getConnection(jdbcUrl, username +, password); System.out.println("Test up to part 2"); System.out.println("Connected to Teradata!"); // Perform your database operations here connectionA.close(); } catch (SQLException e) { // Print the stack trace or error message e.printStackTrace(); System.err.println("SQLException: " + e.getMessage()); } catch (Exception e) { // Handle other exceptions e.printStackTrace(); } } } END # Your Teradata connection details #COMMENTED OUT ON 2/14/24 my $jdbcUrl = "jdbc:teradata://XXX.XX.XXX.XX +/TMODE=TERA,DBS_PORT=1025,CHARSET=UTF8,LOGMECH=LDAP,SSLMODE=ALLOW"; #Here is my JAVA connection String url = "jdbc:teradata://XXX.XX.XXX. +XX/TMODE=TERA,DBS_PORT=1025,CHARSET=UTF8,LOGMECH=LDAP,SSLMODE=ALLOW"; #commented out on 2/16/24 my $jdbcUrl = "jdbc:teradata://XXX.XX.XXX.XX +/TMODE=TERA,DBS_PORT=1025,CHARSET=UTF8,LOGMECH=LDAP,SSLMODE=ALLOW;Ter +aDriver=com.teradata.jdbc.TeraDriver"; my $jdbcUrl = "jdbc:teradata://XXX.XX.XXX.XX/TMODE=TERA,DBS_PORT=1025, +CHARSET=UTF8,LOGMECH=LDAP,SSLMODE=ALLOW"; #my $jdbcUrl = "jdbc:teradata://XXX.XX.XXX.XX/TMODE=TERA,DBS_PORT=1025 +,CHARSET=UTF8,LOGMECH=LDAP,SSLMODE=ALLOW"; my $username = "XXXXX"; my $password = "XXXXXX"; # Call the Java method to test the connection TeradataConnectionTest->testConnection($jdbcUrl, $username, $password) +;

      I believe I am getting closer. Running the below code

      use strict; use warnings; use Inline Java => <<'END'; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.io.PrintWriter; public class TeradataConnectionTest { public static void testConnection(String jdbcUrl, String username, Str +ing password) { try { DriverManager.setLogWriter(new PrintWriter(System.out)); //DriverManager.registerDriver(new com.teradata.jdbc.TeraDriver()); Di +d not work //Class.forName("com.teradata.jdbc.TeraDriver"); Did not work // Class.forName("com.ncr.teradata.TeraDriver"); Did not work Connection connection = DriverManager.getConnection(jdbcUrl, username, + password); System.out.println("Connected to Teradata!"); // Perform your database operations here connection.close(); } catch (SQLException e) { // Print the stack trace or error message e.printStackTrace(); System.err.println("SQLException: " + e.getMessage()); } catch (Exception e) { // Handle other exceptions e.printStackTrace(); } } } END # Your Teradata connection details my $jdbcUrl = "jdbc:teradata://172.28.130.20/TMODE=TERA,DBS_PORT=1025, +CHARSET=UTF8,LOGMECH=LDAP,SSLMODE=ALLOW;TeraDriver=com.teradata.jdbc. +TeraDriver"; my $username = "XXXXX"; my $password = "XXXXX"; # Call the Java method to test the connection TeradataConnectionTest->testConnection($jdbcUrl, $username, $password) +;

      I am receiving the following error:

      DriverManager.getConnection("jdbc:teradata://172.28.130.20/TMODE=TERA, +DBS_PORT=1025,CHARSET=UTF8,LOGMECH=LDAP,SSLMODE=ALLOW;TeraDriver=com. +teradata.jdbc.TeraDriver") registerDriver: io.trino.jdbc.TrinoDriver@2dd9625c DriverManager.initialize: jdbc.drivers = null JDBC DriverManager initialized trying io.trino.jdbc.TrinoDriver getConnection: no suitable driver found for jdbc:teradata://172.28.130 +.20/TMODE=TERA,DBS_PORT=1025,CHARSET=UTF8,LOGMECH=LDAP,SSLMODE=ALLOW; +TeraDriver=com.teradata.jdbc.TeraDriver java.sql.SQLException: No suitable driver found for jdbc:teradata://17 +2.28.130.20/TMODE=TERA,DBS_PORT=1025,CHARSET=UTF8,LOGMECH=LDAP,SSLMOD +E=ALLOW;TeraDriver=com.teradata.jdbc.TeraDriver at java.sql/java.sql.DriverManager.getConnection(DriverManager +.java:708) at java.sql/java.sql.DriverManager.getConnection(DriverManager +.java:230) at TeradataConnectionTest.testConnection(TeradataConnectionTes +t.java:15) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.i +nvoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:577) at InlineJavaUserClassLink.invoke(InlineJavaUserClassLink.java +:11) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.i +nvoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:577) at org.perl.inline.java.InlineJavaUserClassLoader.invoke_via_l +ink(InlineJavaUserClassLoader.java:86) at org.perl.inline.java.InlineJavaUserClassLoader.invoke(Inlin +eJavaUserClassLoader.java:131) at org.perl.inline.java.InlineJavaProtocol.CallJavaMethod(Inli +neJavaProtocol.java:283) at org.perl.inline.java.InlineJavaProtocol.Do(InlineJavaProtoc +ol.java:41) at org.perl.inline.java.InlineJavaServer.ProcessCommand(Inline +JavaServer.java:153) at org.perl.inline.java.InlineJavaServer.ProcessCommand(Inline +JavaServer.java:142) at org.perl.inline.java.InlineJavaServerThread.run(InlineJavaS +erverThread.java:51) SQLException: SQLState(08001) java.sql.SQLException: No suitable driver found for jdbc:teradata://17 +2.28.130.20/TMODE=TERA,DBS_PORT=1025,CHARSET=UTF8,LOGMECH=LDAP,SSLMOD +E=ALLOW;TeraDriver=com.teradata.jdbc.TeraDriver at java.sql/java.sql.DriverManager.getConnection(DriverManager +.java:708) at java.sql/java.sql.DriverManager.getConnection(DriverManager +.java:230) at TeradataConnectionTest.testConnection(TeradataConnectionTes +t.java:15) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.i +nvoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:577) at InlineJavaUserClassLink.invoke(InlineJavaUserClassLink.java +:11) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.i +nvoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:577) at org.perl.inline.java.InlineJavaUserClassLoader.invoke_via_l +ink(InlineJavaUserClassLoader.java:86) at org.perl.inline.java.InlineJavaUserClassLoader.invoke(Inlin +eJavaUserClassLoader.java:131) at org.perl.inline.java.InlineJavaProtocol.CallJavaMethod(Inli +neJavaProtocol.java:283) at org.perl.inline.java.InlineJavaProtocol.Do(InlineJavaProtoc +ol.java:41) at org.perl.inline.java.InlineJavaServer.ProcessCommand(Inline +JavaServer.java:153) at org.perl.inline.java.InlineJavaServer.ProcessCommand(Inline +JavaServer.java:142) at org.perl.inline.java.InlineJavaServerThread.run(InlineJavaS +erverThread.java:51) SQLException: No suitable driver found for jdbc:teradata://172.28.130. +20/TMODE=TERA,DBS_PORT=1025,CHARSET=UTF8,LOGMECH=LDAP,SSLMODE=ALLOW;T +eraDriver=com.teradata.jdbc.TeraDriver

      So, it is almost like it is calling out to the trino driver, not the Teradata driver. How would appropriately register the driver, what is the syntax?