无法通过jdbc连接到teradata数据库(连接中断)

x759pob2  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(563)

我正在尝试连接到teradata数据库,我遵循了文档示例和web上的其他示例,但我无法连接

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

当我尝试使用另一个驱动程序类时,就像他们在官方文档中所说的那样

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

我发现这个问题可能与tdgssconfig.jar有关
但是teradata将这个jar集成到terajdbc4.jar中,所以我迷路了。
terajdbc4和noarch aster jdbc驱动程序的版本如下

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

当使用teradatasqlsassistant实用程序时,我可以用我在代码中输入的相同信息连接到数据库

ia2d9nvy

ia2d9nvy1#

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

相关问题