java-ee – JDBC-Teradata连接中的错误

我试过通过JDBC连接到teredata DB.我正在使用jar的’terajdbc4.jar’和’tdgssconfig.jar’,但我得到了一个ClassNotFoundException和NoClassDefFoundError,因为找不到某种com.ncr.teradata.jtdgss.TdgssManager.

请帮我找一个解决方案.我提供了我的代码片段,后跟错误日志.
用户名和密码是正确的,因为使用该ID通过UNIX连接到teradata DB.

public class HelloTeradataJDBC {


  public static void main(String[] args) throws Exception {

    String url="jdbc:teradata://10.10.***.**/DBS_PORT= 1025/DATABASE= ******/TMODE=ANSI,CHARSET=UTF8";

    try{
    Class.forName("com.ncr.teradata.TeraDriver");
    Connection conn=DriverManager.getConnection(url, "*****", "******");
    //Connection conn=DriverManager.getConnection(connurl, "javauser1", "password1");

    String query="select * from xi.san_emp";


    PreparedStatement stmt=conn.prepareStatement(query);
    ResultSet rs=stmt.executeQuery();
    while(rs.next()) {
        String col1=rs.getString(1);
        System.out.println("col1="+col1);
    }
    }catch(ClassNotFoundException e){
        e.printStackTrace();
    }
  }
}

错误:

Exception in thread "main" java.lang.NoClassDefFoundError: com/ncr/teradata/jtdgss/TdgssManager
    at com.ncr.teradata.TeraEncrypt.getTDgssVersion(TeraEncrypt.java:548)
    at com.ncr.teradata.jdbc_4.parcel.ConfigFeatureTdgss.<init>(ConfigFeatureTdgss.java:44)
    at com.ncr.teradata.jdbc_4.statemachine.InitDBConfigState.action(InitDBConfigState.java:68)
    at com.ncr.teradata.jdbc_4.statemachine.LogonController.run(LogonController.java:50)
    at com.ncr.teradata.jdbc_4.TDSession.<init>(TDSession.java:150)
    at com.ncr.teradata.jdbc_3.ifjdbc_4.TeraLocalConnection.<init>(TeraLocalConnection.java:89)
    at com.ncr.teradata.jdbc.ConnectionFactory.createConnection(ConnectionFactory.java:50)
    at com.ncr.teradata.TeraDriver.connect(TeraDriver.java:214)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at HelloTeradataJDBC.main(HelloTeradataJDBC.java:15)
Caused by: java.lang.ClassNotFoundException: com.ncr.teradata.jtdgss.TdgssManager
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 11 more

最佳答案 这会奏效.驱动程序名称是com.teradata.jdbc.TeraDriver而不是com.ncr.teradata.TeraDriver,我认为这是日期.

Class.forName("com.teradata.jdbc.TeraDriver");
conn = DriverManager.getConnection("jdbc:teradata://"+servername+"/databasename="+this.username+",user="+this.username+",password="+this.password);
点赞