Cannot connect to Teradata database through JDBC (Connection broken)

4.1k views Asked by At

I'm trying to connect to a teradata database, i've followed the documentation example, and other examples on the web, but i cannot connect

    String host= "X"; 
    int port=XXXX;
    String database="X";
    String username = "X";
    String password = "X";
    String url = "jdbc:ncluster://"+host+":"+port+"/"+database;
    
    Properties localProperties = new Properties();
    localProperties.put("user", username);
    localProperties.put("password", password);

    Class.forName("com.asterdata.ncluster.Driver");
    Connection conn = DriverManager.getConnection(url, localProperties);

However with this code i get the following error

Exception in thread "main" java.sql.SQLException: [AsterData][ASTERJDBCDSII](34) : Database connection broken ()
at com.asterdata.ncluster.jdbc.core.NClusterConnection.connect(Unknown Source)
at com.simba.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source)
at com.simba.jdbc.common.AbstractDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at poc.TeradataConnection.main(TeradataConnection.java:31)
Caused by: com.asterdata.ncluster.jdbc.core.MuleException: [AsterData][ASTERJDBCDSII](34) : Database connection broken ()
... 6 more

When i try to use another driver class, like said in their official documentation

String url_teradata = "jdbc:teradata://"+host+"/database="+database
Class.forName("com.teradata.jdbc.TeraDriver");
Connection conn = DriverManager.getConnection(url_teradata,username,password);

I get

Exception in thread "main" java.lang.ExceptionInInitializerError
at com.teradata.jdbc.jdbc.GenericTeraEncrypt.getGSSM(GenericTeraEncrypt.java:577)
at com.teradata.jdbc.jdbc.GenericTeraEncrypt.<init>(GenericTeraEncrypt.java:116)
at com.teradata.jdbc.jdbc.GenericTeradataConnection.<init>(GenericTeradataConnection.java:108)
at com.teradata.jdbc.jdbc_4.TDSession.<init>(TDSession.java:187)
at com.teradata.jdbc.jdk6.JDK6_SQL_Connection.<init>(JDK6_SQL_Connection.java:36)
at com.teradata.jdbc.jdk6.JDK6ConnectionFactory.constructSQLConnection(JDK6ConnectionFactory.java:25)
at com.teradata.jdbc.jdbc.ConnectionFactory.createConnection(ConnectionFactory.java:181)
at com.teradata.jdbc.jdbc.ConnectionFactory.createConnection(ConnectionFactory.java:171)
at com.teradata.jdbc.TeraDriver.doConnect(TeraDriver.java:236)
at com.teradata.jdbc.TeraDriver.connect(TeraDriver.java:162)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at poc.TeradataConnection.main(TeradataConnection.java:36)
Caused by: java.lang.NullPointerException
at com.teradata.tdgss.jtdgss.TdgssConfigApi.GetMechanisms(Unknown Source)
at com.teradata.tdgss.jtdgss.TdgssManager.<init>(Unknown Source)
at com.teradata.tdgss.jtdgss.TdgssManager.<clinit>(Unknown Source)
... 13 more

I've seen that this issue could be related to the tdgssconfig.jar

But teradata integrated this jar into the terajdbc4.jar, so i'm lost.

The versions of the terajdbc4 and the noarch-aster-jdbc-driver are the following

        <dependency>
         <groupId>com.teradata.jdbc</groupId>
         <artifactId>terajdbc4</artifactId>
         <version>16.20.00.10</version>
       </dependency>
       <dependency> 
         <groupId>com.teradata.jdbc</groupId>
         <artifactId>aster-jdbc-driver</artifactId>
         <version>6.10.00.02</version>
       </dependency>  

When using the Teradata SQL Assistant utility, i am able to connect to the database with the same info i put in my code

1

There are 1 answers

0
Sim Hm On BEST ANSWER

As Fred mentioned in his commment, i was missing a version, even if there was the tgssconfig libraries in the teradjdbc4 jar, it wasn't enough, i upgraded the terajdbc to 17.00.00.03 and it worked.