Java 指定的 Oracle URL 无效:OracleDataSource.makeURL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1332869/
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
Invalid Oracle URL specified: OracleDataSource.makeURL
提问by Ticcie
I'm trying to connect to a local oracle database but I'm getting this cryptic error message:
Invalid Oracle URL specified: OracleDataSource.makeURL
.
我正在尝试连接到本地 oracle 数据库,但收到以下神秘错误消息:
Invalid Oracle URL specified: OracleDataSource.makeURL
.
I'm pretty sure this is due to an error with the database connection parameters I'm passing, but really, this error message does not help me in any way. Any hints as to what I'm doing wrong would be greatly appreciated.
我很确定这是由于我传递的数据库连接参数出错,但实际上,此错误消息对我没有任何帮助。任何关于我做错了什么的提示将不胜感激。
FYI: Code used to connect is below, except for the hardcoded strings this is what is used on our production environment and does work there.
仅供参考:用于连接的代码如下,除了硬编码字符串外,这是在我们的生产环境中使用的并且在那里工作。
OracleDataSource dataSource = new OracleDataSource();
dataSource.setServerName("localhost");
dataSource.setUser(userName);
dataSource.setPassword(password);
dataSource.setDatabaseName("orcl");
return dataSource.getConnection();
采纳答案by Ticcie
Surprisingly, after adding the following two lines to the code which created the connection, it worked.
令人惊讶的是,在创建连接的代码中添加以下两行后,它起作用了。
dataSource.setPortNumber(1521);
dataSource.setDriverType("thin");
I don't understand why we did not have that problem before, but that may have something to do with my local install. My biggest beef is with the error message not giving any detail about what is wrong though.
我不明白为什么我们以前没有这个问题,但这可能与我的本地安装有关。我最大的问题是错误消息没有提供任何关于错误的细节。
回答by Kalpesh Soni
if you use setUrl (or if your container like glassfish does it)
如果您使用 setUrl (或者如果您的容器如 glassfish 这样做)
make sure you use correct syntax
确保使用正确的语法
==== Notice the colon before @====
====注意@====前的冒号
jdbc:oracle:thin:@localhost:1521:sid
jdbc:oracle:thin:@localhost:1521:sid
or
或者
jdbc:oracle:thin:@localhost:1521/servicename
jdbc:oracle:thin:@localhost:1521/servicename
The datasource class tries to parse it and gives cryptic error if syntax has issues
数据源类尝试解析它并在语法有问题时给出神秘错误
回答by Mirimas
For WildFlyusers (v14.0.1.Final currently).
对于WildFly用户(当前为v14.0.1.Final)。
You need to add additional parametersfor DataSource:
您需要为 DataSource添加其他参数:
DataSource -> Connection -> Connection Properties
数据源 -> 连接 -> 连接属性
driverType=thin(press Enter to complite).
driverType=thin(按 Enter 完成)。
Also doublecheck you use right type of DataSource. In my case problem was solved by creating XA DataSource and pass URL to parameter.
还要仔细检查您使用正确类型的数据源。在我的例子中,问题是通过创建 XA 数据源并将 URL 传递给参数来解决的。