【问题标题】:How can I connect to a web based Oracle database with Java?如何使用 Java 连接到基于 Web 的 Oracle 数据库?
【发布时间】:2009-11-24 22:35:39
【问题描述】:

我有一个帐户、密码和 URL。

【问题讨论】:

标签: java database oracle oracle10g


【解决方案1】:

用途:

Connection connection = null;

try {
   // Load the JDBC driver
   String driverName = "oracle.jdbc.driver.OracleDriver";
   Class.forName(driverName);

   // Create a connection to the database
   String serverName = "127.0.0.1";
   String portNumber = "1521";
   String sid = "mydatabase";
   String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
   String username = "username";
   String password = "password";
   connection = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
   // Could not find the database driver
} catch (SQLException e) {
   // Could not connect to the database
}

参考:Connecting to an Oracle Database

【讨论】:

    【解决方案2】:

    只是对 OMG Ponies 答案的补充,您需要几项才能继续: 1. 构建路径上的 Oracle JDBC 驱动程序(Oracle 提供这些驱动程序供下载) 2. OMG Ponies 代码中的 driverName 变量必须更改为您正在使用的特定 Oracle 驱动程序的名称 3. OMG Ponies 代码中的serverName 变量不应保留在127.0.0.1,而应改为您提到的服务器地址。我之所以注意到这一点,是因为您提出问题的方式意味着不熟悉一般的计算机概念,尤其是使用带有 Java 的数据库。

    【讨论】:

    • +1 了解详情。另外,在整个答案中阅读 OMG Ponies 很有趣。
    • 是的,这是第一次使用 Java 使用数据库,老实说,我不是世界上最强大的程序员。你说的司机是什么意思?知道我需要哪一个吗?感谢您的帮助和时间。
    • 当然是与您使用的 JDK 最匹配的 Oracle 驱动程序。
    • 我在 Oracle 方面的有限经验告诉我,您需要获得专门用于您要连接到的数据库的 Oracle 版本的 Oracle JDBC 驱动程序。例如,如果您要连接到 Oracle 10g DB,则需要 Oracle 10g JDBC 驱动程序。您可以在oracle.com/technology/software/tech/java/sqlj_jdbc/index.html查看要下载的驱动程序列表。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-30
    • 2020-09-20
    • 1970-01-01
    • 2021-11-24
    • 2016-09-28
    • 1970-01-01
    相关资源
    最近更新 更多