我使用eclipse和java连接到oracle 12c数据库。但每次我执行该过程时,都会出现连接失败错误,内容如下:
java.sql.SQLException:指定了无效的Oracle URL
以下是我的代码:
import java.sql.*;
public class JdbcConnection {
public static void main(String[] args) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin@localhost:1521:xe", "username", "password");
Statement statement = con.createStatement();
String sql = "select * from employees";
ResultSet rs = statement.executeQuery(sql);
while (rs.next())
System.out.println(rs.getInt(3) + " " + rs.getString(2));
con.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
我使用的是Windows 7 sp1 Ultimate(64位)
CPU:i5 2.85 ghz
RAM:8GB
Oracle安装在单独的硬盘驱动器中(在同一台计算机中)。
编辑:
我已经尝试过这篇文章的第一个建议:How do you find out the Oracle database's URL?
我收到一条错误消息:
ORA-00928:SELECT KEYWORD MISSING ...
当我在启动菜单上运行oracle“SQL DEVELOPER”应用程序并从上面的帖子中键入建议时,会发生此错误。 注意:我想从eclipse连接到数据库并以编程方式查询它。 有没有办法找出正确的连接URL是什么? 请帮忙。