MATLAB MySQL Database connection error

4 ビュー (過去 30 日間)
Vasan V S
Vasan V S 2019 年 3 月 29 日
編集済み: Kojiro Saito 2019 年 3 月 29 日
I have followed the MySQL Connector documentation for installing the driver and setting it up. Using the Database explorer, I have added a configuration data source called localdb. I have also created a database and a table with sample insertions into it. use the the Database explorer, I have verified that I am able to successfully use the configurator and run all kinds of DB queries.
While running inside the MATLAB,the following is my sample code snippet:
conn = database('localdb','root','');
selectquery = 'SELECT * FROM <Table Name>';
data = select(conn,selectquery)
On executing the code in MATLAB, I get an error stating that
Error using database.odbc.connection/select (line 74)
Invalid connection.
When I see the conn.Message, I get the following string:
ans =
'ODBC is not supported on Unix. Please use a JDBC driver.'
My localdb data source has been configured a JDBC data source only and not as ODBC. I am running it on Ubuntu 18.04
The documentation for running the connection is also mentioning as given above.
Can someone please provide a clue on what is wrong here?
Thanks in advance

採用された回答

Kojiro Saito
Kojiro Saito 2019 年 3 月 29 日
編集済み: Kojiro Saito 2019 年 3 月 29 日
In order to specify JDBC, add key-value pairs to database function (ref: document).
conn = database('localdb','root','', 'Vendor','MySQL', 'Server','localhost', 'PortNumber', 3306);
You can omit Server and PortNumber when the database server is localhost and port number is default.

その他の回答 (1 件)

Vasan V S
Vasan V S 2019 年 3 月 29 日
Thanks a ton Kojiro. This worked perfectly.
I guess this has to be getting updated in the documentation fully.

Community Treasure Hunt

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

Start Hunting!

Translated by