如何从 IntelliJ IDEA 14 连接到 Oracle 数据库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27808540/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 02:40:56  来源:igfitidea点击:

How to connect to an Oracle database from IntelliJ IDEA 14?

javaoracleintellij-ideadatabase-connection

提问by MaXiMkA

Could someone tell me exactly how could I manage this connection? I am doing this for like 3 days now and every example, every video on the net is about MySQL or SQLite connection with NetBeans. My goal is to put the results of a SELECT query in a JTable. Nothing more. I know I need some driver and connection URL, ResultSet, PreparedStatement, TableModel, but I didn't manage to find the perfect combination to get some results.

有人能确切地告诉我如何管理这种连接吗?我已经这样做了大约 3 天,每个例子,网络上的每个视频都是关于 MySQL 或 SQLite 与 NetBeans 的连接。我的目标是将 SELECT 查询的结果放在 JTable 中。而已。我知道我需要一些驱动程序和连接 URL、ResultSet、PreparedStatement、TableModel,但我没有设法找到获得一些结果的完美组合。

Thanks.

谢谢。

回答by Stephen C

If you can't find a tutorial or video that covers all of this, then you need to combine sources that cover the individual parts of the problem.

如果您找不到涵盖所有这些内容的教程或视频,那么您需要合并涵盖问题各个部分的来源。

For example:

例如:

回答by egallardo

You may be struggling with all the options on the IntelliJ dialog. Most IDEs provide a way to specify the JDBC URL. If you are familiar with Oracle TNS names the below URLs will work for you when you have a complex Oracle address list (as in RAC, for instance) or when there is a firewall and you must specify SERVER=DEDICATED:

您可能正在为 IntelliJ 对话框中的所有选项而苦恼。大多数 IDE 提供了一种指定 JDBC URL 的方法。如果您熟悉 Oracle TNS 名称,那么当您拥有复杂的 Oracle 地址列表(例如在 RAC 中)或存在防火墙并且您必须指定时,以下 URL 将适用于您SERVER=DEDICATED

jdbc:oracle:thin:@(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = yourdbhost.com)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))

or

或者

jdbc:oracle:thin:@(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = yourdbhost.com)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SID = XE)))

In most simple cases this will suffice:

在大多数简单的情况下,这就足够了:

jdbc:oracle:thin:@yourdbhost.com:1521:XE

Finally, make sure your username and password work by testing them with SQL/PLUS

最后,通过使用 SQL/PLUS 测试您的用户名和密码来确保它们有效