Matlab generates a wrong oracle database url

I try to connect to an Oracle database (ojdbc8). The following lines work fine:
url='jdbc:oracle:thin:@servername:1532/SID';
driver='oracle.jdbc.driver.OracleDriver';
conn = database('databasename','username','password',driver,url)
However using the following one
conn = database('databasename','username','password','Vendor','Oracle','Server','servername','PortNumber',1532,'DriverType','thin')
generates an error message
'Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently know of SID given in connect descripto'.
It appears than that the Matlab function database.internal.utilities.DatabaseUtils.getDatabaseURL(vendor) generates the wrong url: 'jdbc:oracle:thin:@servername:1532:SID' instead of 'jdbc:oracle:thin:@servername:1532/SID. I tried also to use the app Database Explorer and got the same error. I guess this is due to the same problem. How to change the way Matlab generates the url?

回答(1 个)

Hi,
There are two notations for connection with a thin driver to an Oracle database (see also JDBC - Oracle FAQ (orafaq.com)):
  1. SID (old not recommended): jdbc:oracle:thin:[<user>/<password>]@<host>[:<port>]:<SID>
  2. Service: jdbc:oracle:thin:[<user>/<password>]@//<host>[:<port>]/<service>
This is probably where the confusion is coming from. As using the service name is better I think MATLAB should update this.

类别

帮助中心File Exchange 中查找有关 Reporting and Database Access 的更多信息

产品

版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by