Errors obtaining jdbc:default:connection from external Java stored procedure

Connectivity

Errors obtaining jdbc:default:connection from external Java stored procedure

I wrote a Java stored procedure, packed it into a jar and installed it into the Teradata database. I want to use the default database connection as described here [1]. Most of the code was generated by the Teradata wizard for stored procedures.

public class TestSql {
public static void getEntryById(int id, String[] resultStrings) throws SQLException {
Connection con = DriverManager.getConnection("jdbc:default:connection");

String sql = "SELECT x FROM TEST_TABLE WHERE ID = " + id + ";";

Statement stmt = (Statement) con.createStatement();
ResultSet rs1 = ((java.sql.Statement) stmt).executeQuery(sql);
rs1.next();
String resultString = rs1.getString(1);
stmt.close();
con.close();

resultStrings[0] = resultString;
}
}

I installed the jar:

CALL SQLJ.REPLACE_JAR('CJ!/my/path/Teradata-SqlTest.jar','test');

And created the procedure:

REPLACE PROCEDURE "db"."getEntryById" (
IN "id" INTEGER,
OUT "resultString" VARCHAR(1024))
LANGUAGE JAVA
MODIFIES SQL DATA
PARAMETER STYLE JAVA
EXTERNAL NAME 'test:my.package.TestSql.getEntryById(int,java.lang.String[])';

Now when I call this procedure, I get this error message:

Executed as Single statement.  Failed [7827 : 39001] Java SQL Exception SQLSTATE 39001: Invalid SQL state (08001: No suitable driver found for jdbc:default:connection).

Now when I log off from Teradata and log on again and call the procedure, the error message becomes:

Executed as Single statement.  Failed [7827 : 39001] A default connection for a Java Stored Procedure has not been established for this thread.).

What is the problem here? I'm connecting to Teradata using the Eclipse plugin. Teradata v. 15.0.1.01.

Thank you,

Björn

[1]: http://www.info.teradata.com/HTMLPubs/DB_TTU_14_00/index.html#page/SQL_Reference/B035_1147_111A/ch05...

2 REPLIES

Re: Errors obtaining jdbc:default:connection from external Java stored procedure

After many hours I finally found the problem. Eclipse packed all dependencies into the jar - which basically is ok. However it also packed the Teradata JDBC driver files (tdgssconfig.jar and terajdbc4.jar) into the result jar, which was the problem.

I adjusted the jar building process so that these files are not included and the errors went away.

Teradata Employee

Re: Errors obtaining jdbc:default:connection from external Java stored procedure

Correct -- you should not include terajdbc4.jar and tdgssconfig.jar within your jar file that contains your stored procedure.