Connecting to database

9 visualizzazioni (ultimi 30 giorni)
Oyinda
Oyinda il 19 Apr 2011
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 Commento
Oleg Komarov
Oleg Komarov il 19 Apr 2011
Check with javaclasspath that the path was added correctly. All the patsh should look stacked.

Accedi per commentare.

Risposte (1)

Chirag Gupta
Chirag Gupta il 19 Apr 2011
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

Community Treasure Hunt

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

Start Hunting!

Translated by