有人可以建议我在这里做错了什么吗:
收到错误消息“SQL 状态:08001 未找到适合 jdbc:oracle:thin:@128:23:44:01:12345:pppp_rr 的驱动程序已拾取 JAVA_TOOL_OPTIONS: -Duser.home=C:\Users\123ert"
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JDBCExample {
public static void main(String[] args) {
try (Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@128:23:44:01:12345:pppp_rr", "Test123", "********")) {
if (conn != null) {
System.out.println("Connected to the database!");
} else {
System.out.println("Failed to make connection!");
}
} catch (SQLException e) {
System.err.format("SQL State: %s\n%s", e.getSQLState(), e.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
}
}
最佳答案
我无法使用 Oracle 数据库实际测试它,但我知道在建立连接之前必须注册一个驱动程序。检查以下代码,这基本上是您的代码加上驱动程序注册。
public static void main(String args[]) throws Exception {
// registration for the driver, it's needed,
// otherwise there will be "no suitable driver found"
Class.forName("oracle.jdbc.driver.OracleDriver");
try (Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@128:23:44:01:12345:pppp_rr", "Test123", "********")) {
if (conn != null) {
System.out.println("Connected to the database!");
} else {
System.out.println("Failed to make connection!");
}
} catch (SQLException e) {
System.err.format("SQL State: %s\n%s", e.getSQLState(), e.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
}
关于java - 收到错误“SQL 状态 : 08001 No suitable driver found for jdbc:oracle:thin:@128:23:44:01:12345:pppp_rr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57165433/