toscanelli
toscanelli

Reputation: 1241

How can I define username and password in the URL connection string?

All I have read in oracle doc is that I can replace this:

OracleDataSource ods = new OracleDataSource();
ods.setDriverType("thin");
ods.setServerName("localhost");
ods.setNetworkProtocol("tcp");
ods.setDatabaseName("databaseName");
ods.setPortNumber(1521);
ods.setUser("userName");
ods.setPassword("Password");

by this:

ods.setUser("userName");
ods.setPassword("Password");
ods.setURL("jdbc:oracle:thin:@(DESCRIPTION=(ENABLE=broken)(LOAD_BALANCE = yes)(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVER=dedicated)(SERVICE_NAME=xxxx)(FAILOVER_MODE =(TYPE = SELECT)(METHOD = BASIC)(RETRIES = 10)(DELAY = 1))))");

But I am wondering whether is possible include everything in one string to store all together in a config file or not, i.e., everything set with ods.setURL().

Upvotes: 1

Views: 2970

Answers (1)

acesargl
acesargl

Reputation: 569

ods.setURL("jdbc:oracle:thin:userName/Password@(DESCRIPTION=(ENABLE=broken)(LOAD_BALANCE = yes)(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVER=dedicated)(SERVICE_NAME=xxxx)(FAILOVER_MODE =(TYPE = SELECT)(METHOD = BASIC)(RETRIES = 10)(DELAY = 1))))");

Upvotes: 1

Related Questions