Ticcie
Ticcie

Reputation: 810

Invalid Oracle URL specified: OracleDataSource.makeURL

I'm trying to connect to a local oracle database but I'm getting this cryptic error message: 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();

Upvotes: 17

Views: 82975

Answers (3)

Mirimas
Mirimas

Reputation: 737

For WildFly users (v14.0.1.Final currently).

You need to add additional parameters for DataSource:

DataSource -> Connection -> Connection Properties

driverType=thin (press Enter to complite).

Also doublecheck you use right type of DataSource. In my case problem was solved by creating XA DataSource and pass URL to parameter.

Upvotes: 1

Kalpesh Soni
Kalpesh Soni

Reputation: 7287

if you use setUrl (or if your container like glassfish does it)

make sure you use correct syntax

==== Notice the colon before @ ====

jdbc:oracle:thin:@localhost:1521:sid

or

jdbc:oracle:thin:@localhost:1521/servicename

The datasource class tries to parse it and gives cryptic error if syntax has issues

Upvotes: 32

Ticcie
Ticcie

Reputation: 810

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.

Upvotes: 19

Related Questions