简体   繁体   English

oracle.jdbc.driver.T4CConnection.getSchema()异常

[英]oracle.jdbc.driver.T4CConnection.getSchema() exception

I am trying get the default database name from the connection for oracle我正在尝试从 oracle 的连接中获取默认数据库名称

The following code gives me this abstract method error.下面的代码给了我这个抽象方法错误。 Can anyone suggest me how I can get default database name using jdbc?谁能建议我如何使用 jdbc 获取默认数据库名称?

environmental information version环境信息版

oracle:Oracle 11g
java:1.8

pom.xml pom.xml

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <maven.compiler.target>${java.version}</maven.compiler.target>
  </properties>
  <dependencies>
    <dependency>
      <groupId>com.oracle</groupId>
      <artifactId>ojdbc6</artifactId>
      <version>11.2.0.3</version>
    </dependency>
  </dependencies>

code代码

package snippet;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectiongetSchemaErrorTest {
  public static void main(String[] args) {
    String driver = "oracle.jdbc.driver.OracleDriver";
    String url = "jdbc:oracle:thin:@xx:8095/orcl";
    String user = "xx";
    String pswd = "xx";

    try {
      Class.forName(driver);
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }

    Connection connection = null;
    try {
      connection = DriverManager.getConnection(url, user, pswd);
      System.out.println(connection.getClass().getName());
      String schema = connection.getSchema();
      System.out.println(schema);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        connection.close();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }
}

error错误

oracle.jdbc.driver.T4CConnection
Exception in thread "main" java.lang.AbstractMethodError: oracle.jdbc.driver.T4CConnection.getSchema()Ljava/lang/String;
    at snippet.ConnectiongetSchemaErrorTest.main(ConnectiongetSchemaErrorTest.java:24)

getSchema() method is only available in Java 7 and above but ojdbc6.jar is compiled with Java 6 where as ojdbc8.jar is compiled with Java 8 . getSchema()方法仅在Java 7及更高版本中可用,但ojdbc6.jar是用Java 6编译的,而ojdbc8.jar是用Java 8编译的。 Either use ojdbc8.jar or alternatively you can try the code below with ojdbc6.jar使用ojdbc8.jar或者您可以使用ojdbc6.jar尝试下面的代码

   // For ojdbc6.jar
   String schema= connection.getMetaData().getUserName();
   System.out.println("Schema Name is : " + schema);

   or 
 
    DatabaseMetaData dbmd = connection.getMetaData();
   String schema=dbmd.getUserName();
   System.out.println("Schema Name is : " + schema);
 

The official supported Oracle JDBC versions from 11.2.0.4, 12.2.0.2, 18.3.0.0, 19.3.0.0,19.6.0.0, and 19.7.0.0 are available on Central Maven Repository.官方支持 Oracle JDBC 11.2.0.4、12.2.0.2、18.3.0.0、19.3.0.0、19.6.0.0、19.7.0.0 版本可在Central Maven Repository 获取。 Refer to Maven Central Guide for more details.详情请参阅Maven 中央指南

It is recommended to use the latest version.建议使用最新版本。 Check out FAQ for JDK compatibility.查看 JDK 兼容性的常见问题解答

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在oracle.jdbc.driver.T4CConnection上找到锁定的对象 - Locked object found on oracle.jdbc.driver.T4CConnection java.io.NotSerializableException-oracle.jdbc.driver.T4CConnection - java.io.NotSerializableException - oracle.jdbc.driver.T4CConnection 表类型的调用过程。 创建结构时发生异常:java.lang.AbstractMethodError:oracle.jdbc.driver.T4CConnection.createStruct - Call procedure with a table type. Exception while create Struct: java.lang.AbstractMethodError: oracle.jdbc.driver.T4CConnection.createStruct Oracle 驱动程序错误 oracle.jdbc.driver.T4CConnection.isValid(I)Z - Oracle Driver Error oracle.jdbc.driver.T4CConnection.isValid(I)Z 无法将JAVA / Oracle-weblogic.jdbc.wrapper.poolconnection_oracle_jdbc_driver_t4cconnection强制转换为oracle.jdbc.driver.oracleconnection - JAVA/Oracle-weblogic.jdbc.wrapper.poolconnection_oracle_jdbc_driver_t4cconnection cannot be cast to oracle.jdbc.driver.oracleconnection 使用解包的oracle.jdbc.driver.T4CConnection的HikariCP连接泄漏 - HikariCP Connection Leak using unwrapped oracle.jdbc.driver.T4CConnection java.lang.ClassCastException:oracle.jdbc.driver.T4CConnection无法转换为com.arjuna.ats.internal.arjuna.recovery.Connection - java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection cannot be cast to com.arjuna.ats.internal.arjuna.recovery.Connection Maven编译和运行时错误java.lang.AbstractMethodError:Tomcat 8 Server上的oracle.jdbc.driver.T4CConnection.isValid(I)Z - Maven compilation and run time error java.lang.AbstractMethodError: oracle.jdbc.driver.T4CConnection.isValid(I)Z on Tomcat 8 Server 找不到类异常-oracle.jdbc.driver.OracleDriver - Class not found exception - oracle.jdbc.driver.OracleDriver 初学者Java的oracle.jdbc.driver.OracleDriver异常 - oracle.jdbc.driver.OracleDriver exception for Beginners Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM