필터 지우기
필터 지우기

Connecting to MySQL database

조회 수: 1 (최근 30일)
vish
vish 2011년 2월 2일
I am trying to connect to a MySQL database using the Database Toolbox in matlab but I am getting some errors connecting. Please let me know if I have to connect any MySQL connectors.
Database name: ec09249
conn = database ('jdbc:mysql://localhost/ec09249','root','');
curs = exec(conn,'select *from dtm');
curs=fetch(curs);
OUTPUT:
conn =
Instance: 'jdbc:mysql://localhost/ec09249'
UserName: 'root'
Driver: []
URL: []
Constructor: [1x1 com.mathworks.toolbox.database.databaseConnect]
Message: '[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified Please verify that login information and database url are valid.'
Handle: 0
TimeOut: []
AutoCommit: 'off'
Type: 'Database Object'
EDIT: I also tried by loading the MySQL drivers but it vain. conn = database ('ec09249','root','','com.mysql.jdbc.Driver','jdbc:mysql://localhost:3306/ec09249')
  댓글 수: 1
Martijn
Martijn 2011년 2월 2일
The first syntax you used was definitely not correct. The second attempt looks better but which exact error messages do you receive with the second syntax which you tried?

댓글을 달려면 로그인하십시오.

채택된 답변

the cyclist
the cyclist 2011년 2월 2일
It has been forever since I set up my database toolbox, so I honestly don't remember all the details. But I have a couple differences from you.
Your second attempt, where you specify the driver, is closer to my syntax. I am pretty sure you do not want to specify the database name again in the driver string, though, because MATLAB is going to append that. You should end that string with the slash just after the port number.
The only other thing I have in my setup that looks different from what you are doing is a specification of the path to my JAR, before the database command:
javaaddpath('{path to Java archive file}/postgresql-8.3-604.jdbc3.jar')
  댓글 수: 1
vish
vish 2011년 2월 3일
Thank you for the answer. I was missing the javaaddpath. Btw. I have to specify the database name in database URL in order to connect to the database. Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by