【发布时间】:2015-08-19 00:09:28
【问题描述】:
我使用 Oracle 11g 的数据库表创建了一个 Java Eclipse 应用程序。它工作正常,但只在我的本地电脑上。我怎样才能让这些表在另一台电脑上工作?也许我必须将它们放在应用程序文件夹中?应用通过 JDBC 连接器与数据库连接。
连接逻辑如下:
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch (ClassNotFoundException e) {
System.out.println("Unable to load the driver class!");
}
String url = "jdbc:oracle:thin:@localhost:1521:xe";
String user = "system";
String password = "xxxxpw";
Connection connection = null;
try {
connection = DriverManager.getConnection(url, user, password);
System.out.println("Connection succeed!!");
}
catch (SQLException e) {
System.out.println("Couldn't take connection!");
}
【问题讨论】:
-
Oracle 数据库服务器在哪里运行? “将表格放入应用程序文件夹”是什么意思?这些表驻留在数据库中,而不是某个文件夹中(当然,除非它们实际上不是数据库表,而是例如转储文件、从表创建的 csv 文件或其他什么?
-
oracle 数据库在我的本地电脑中运行。是的,这些表位于 db 中,而不是任何其他文件夹中。
-
只是猜测,但是您是否将 JDBC 连接配置为使用 127.0.0.1 或 localhost 作为数据库地址?如果是这样,请将其替换为您机器的外部地址。