JDBC connection.getschema() AbstractMethodError

2019-07-31 04:22发布

问题:

I am trying get the default database name from the connection for Teradata. I am using Teradata JDBC Driver 15.10.00.33.

The following code gives me this abstract method error. Can anyone suggest me how I can get default database name using jdbc?

Exception in thread "main" java.lang.AbstractMethodError: com.teradata.jdbc.jdk6.JDK6_SQL_Connection.getSchema()Ljava/lang/String;
public class TestTDConnection {

    public static void main(String args[]) {

        String tdConnString = "jdbc:teradata://xx/database=xx";

        try {
            Connection conn = DriverManager.getConnection(tdConnString,"xx","xx");
            System.out.println(conn.getSchema());
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

回答1:

If you look at the javadoc for getSchema(), you will notice the following:

Since:
1.7

That means you need a Java 7 driver, and the classname in the error message is an obvious indication that you're using a Java 6 driver:

com.teradata.jdbc.jdk6.JDK6_SQL_Connection

Replace the driver .jar file with a Java 7 (JDBC 4.1) compliant driver.

Or don't use Java 7 features.