繁体   English   中英

如何使用Java连接到基于Web的Oracle数据库?

[英]How can I connect to a web based Oracle database with Java?

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

采用:

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
}

参考: 连接到Oracle数据库

只是OMG Ponies答案的附录,您将需要执行以下两项操作:1.构建路径上的Oracle JDBC驱动程序(Oracle提供了这些驱动程序供下载)2. OMG Ponies代码中的driverName变量必须更改为您正在使用的特定Oracle驱动程序的名称。3. OMG Ponies代码中的serverName变量不应保留为127.0.0.1,而应更改为您提到的服务器地址。 我之所以仅注意这一点,是因为您表达问题的方式暗示着对计算机概念的不熟悉,尤其是对Java的数据库的不熟悉。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM