Friday, February 3, 2012

Matlab database drivers

1- I found out the following link which is very important to get the drivers:
http://www.mathworks.com/support/solutions/en/data/1-CL94AW/index.html?product=DB&solution=1-CL94AW

another good link is:
http://www.mathworks.com/help/toolbox/database/ug/database.html

2- open matlab as an administrator and on the command window type:
edit classpath.txt
3- add the path of the driver to the end of the text file
4- save
5- restart
and you are ready to rock the matlab database world.
good luck
I am placing a small example below to how to connect to a MS SQL database:

s.DataReturnFormat = 'cellarray';
s.ErrorHandling = 'store';
s.NullNumberRead = 'NaN';
s.NullNumberWrite = 'NaN';
s.NullStringRead = 'null';
s.NullStringWrite = 'null';
s.JDBCDataSourceFile = '';
s.UseRegistryForSources = 'yes';
s.TempDirForRegistryOutput = 'C:\Users\XOXO\AppData\Local\Temp';
s.DefaultRowPreFetch = '1000000';
setdbprefs(s)

url = 'jdbc:sqlserver://PORT_NAME.local;database=DATABASENAME';
conn = database(' DATABASENAME ', ' DATABASE  USER NAME', 'DATABASE PASSWORD', 'com.microsoft.sqlserver.jdbc.SQLServerDriver', url);