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


all have read in oracle doc 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 wondering whether possible include in 1 string store in config file or not, i.e., set ods.seturl().

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))))"); 

Comments