[英]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.