Connecting to database

9 次查看(过去 30 天)
Oyinda
Oyinda 2011-4-19
After setting the classpath for JDBC I did a test drive. The output was:
Current JDBC Drivers: null
sun.jdbc.odbc.JdbcOdbcDriver@723d7c
I have also made changes to my classpath.txt by adding this at the end.
C:/Program Files (x86)/Java/mysql-connector-java-5.1.15/mysql-connector-java-5.1.15-bin.jar
so i did all this.
>> url = 'jdbc:mysql://localhost/test';
>> conn = database('characters', 'root', '', 'com.mysql.jdbc.Driver', url);
>> conn
conn =
Instance: 'characters'
UserName: 'root'
Driver: []
URL: []
Constructor: [1x1 com.mathworks.toolbox.database.databaseConnect]
Message: [1x66 char]
Handle: 0
TimeOut: []
AutoCommit: 'off'
Type: 'Database Object'
>> ping(conn)
??? Error using ==> database/ping
Cannot pass a null connection handle
But I get this error. What is happening and how can I solve it?
  1 个评论
Oleg Komarov
Oleg Komarov 2011-4-19
Check with javaclasspath that the path was added correctly. All the patsh should look stacked.

请先登录,再进行评论。

回答(1 个)

Chirag Gupta
Chirag Gupta 2011-4-19
Expand the Message field in the conn object. This will give you the actual reported error. For a successful connection, you will notice that the Message field is empty.
Typically the jdbc url for mysql is:
jdbc:mysql://<machine>:<port>/databasename');
I am guessing it should be: jdbc::mysql://localhost:3306/characters
Where 3306 is the general default port for mySQl

类别

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