无法通过 JDBC 连接到 Teradata 数据库(连接断开)

Cannot connect to Teradata database through JDBC (Connection broken)

我正在尝试连接到 teradata 数据库,我已经按照 documentation example 和网络上的其他示例进行操作,但我无法连接

    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);

但是使用这段代码我得到以下错误

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

当我尝试使用另一个驱动程序时 class,如他们所说 official documentation

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

我明白了

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

我发现这个问题可能与

但是 teradata 将这个 jar 集成到 terajdbc4.jar,所以我迷路了。

terajdbc4 和 noarch-aster-jdbc-driver 的版本如下

        <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>  

使用 Teradata SQL Assistant 实用程序时,我能够使用我在代码中输入的相同信息连接到数据库

正如 Fred 在他的评论中提到的,我缺少一个版本,即使 teradjdbc4 jar 中有 tgssconfig 库,这还不够,我将 terajdbc 升级到 17.00.00.03 并且它工作了。