Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
SQL Server and JDBC drivers

Subject: SQL Server and JDBC drivers

From: Darik

Date: 8 Jan, 2009 23:28:02

Message: 1 of 5

I'm trying to connect to a MS SQL Server 2005 database. I downloaded the JDBC driver from here: http://msdn.microsoft.com/en-us/data/aa937724.aspx

Here's my code:

javaaddpath('G:\jdbc\sqljdbc_1.2\enu\sqljdbc.jar')
db = database('testdb1', 'dg', 'pass', 'com.microsoft.jdbc.sqlserver.SQLServerDriver',...
    'jdbc:microsoft:sqlserver://localhost:1433;database=testdb1')

Which returns the message:

JDBC Driver Error: com.microsoft.jdbc.sqlserver.SQLServerDriver. Driver Not Found/Loaded.

Do I have to do something with the driver other than list it on the java class path?

Subject: SQL Server and JDBC drivers

From: Ed Yu

Date: 20 Mar, 2009 20:21:02

Message: 2 of 5

Hi Darik,

I've found that javaaddpath might not work 100% properly with JDBC drivers. The best way is to use javaclasspath(). Beware that when using javaclasspath(), it resets all global variables within your workspace so the best place to invoke javaclasspath is at the begining of your MATLAB code execution.

"Darik" <dgambleDEL@uwaterlooDEL.caDEL> wrote in message <gk6262$nu6$1@fred.mathworks.com>...
> I'm trying to connect to a MS SQL Server 2005 database. I downloaded the JDBC driver from here: http://msdn.microsoft.com/en-us/data/aa937724.aspx
>
> Here's my code:
>
> javaaddpath('G:\jdbc\sqljdbc_1.2\enu\sqljdbc.jar')
> db = database('testdb1', 'dg', 'pass', 'com.microsoft.jdbc.sqlserver.SQLServerDriver',...
> 'jdbc:microsoft:sqlserver://localhost:1433;database=testdb1')
>
> Which returns the message:
>
> JDBC Driver Error: com.microsoft.jdbc.sqlserver.SQLServerDriver. Driver Not Found/Loaded.
>
> Do I have to do something with the driver other than list it on the java class path?

Subject: SQL Server and JDBC drivers

From: Yair Altman

Date: 21 Mar, 2009 17:41:01

Message: 3 of 5

Matlab's default classloader does not access the dynamic classpath for some reason. This issue was already reported a few times in the past regarding JDBC. MathWorks say that it is not a bug but an expected behavior (http://www.mathworks.com/support/solutions/data/1-1YFUFB.html?solution=1-1YFUFB ) - Ok….

This problem and its solution apparently occur even when database connectivity is done directly by invoking the relevant Java/JDBC methods, not just in the DB Toolbox. It does not depend on the driver, but on the way Matlab's classloader works - a very basic Matlab issue.

The easy solution is to add the driver's class or JAR file(s) to Matlab's static classpath within $MATLAB/Toolbox/local/classpath.txt and it should work after restarting Matlab.

Yair Altman
http://undocumentedmatlab.com
 


"Ed Yu" <ekyu88@hotmail.com> wrote in message <gq0tre$qtr$1@fred.mathworks.com>...
> Hi Darik,
>
> I've found that javaaddpath might not work 100% properly with JDBC drivers. The best way is to use javaclasspath(). Beware that when using javaclasspath(), it resets all global variables within your workspace so the best place to invoke javaclasspath is at the begining of your MATLAB code execution.
>
> "Darik" <dgambleDEL@uwaterlooDEL.caDEL> wrote in message <gk6262$nu6$1@fred.mathworks.com>...
> > I'm trying to connect to a MS SQL Server 2005 database. I downloaded the JDBC driver from here: http://msdn.microsoft.com/en-us/data/aa937724.aspx
> >
> > Here's my code:
> >
> > javaaddpath('G:\jdbc\sqljdbc_1.2\enu\sqljdbc.jar')
> > db = database('testdb1', 'dg', 'pass', 'com.microsoft.jdbc.sqlserver.SQLServerDriver',...
> > 'jdbc:microsoft:sqlserver://localhost:1433;database=testdb1')
> >
> > Which returns the message:
> >
> > JDBC Driver Error: com.microsoft.jdbc.sqlserver.SQLServerDriver. Driver Not Found/Loaded.
> >
> > Do I have to do something with the driver other than list it on the java class path?

Subject: SQL Server and JDBC drivers

From: Vladlen Gusman

Date: 28 Apr, 2009 19:15:18

Message: 4 of 5

"Ed Yu" <ekyu88@hotmail.com> wrote in message <gq0tre$qtr$1@fred.mathworks.com>...
> Hi Darik,
>
> I've found that javaaddpath might not work 100% properly with JDBC drivers. The best way is to use javaclasspath(). Beware that when using javaclasspath(), it resets all global variables within your workspace so the best place to invoke javaclasspath is at the begining of your MATLAB code execution.
>
> "Darik" <dgambleDEL@uwaterlooDEL.caDEL> wrote in message <gk6262$nu6$1@fred.mathworks.com>...
> > I'm trying to connect to a MS SQL Server 2005 database. I downloaded the JDBC driver from here: http://msdn.microsoft.com/en-us/data/aa937724.aspx
> >
> > Here's my code:
> >
> > javaaddpath('G:\jdbc\sqljdbc_1.2\enu\sqljdbc.jar')
> > db = database('testdb1', 'dg', 'pass', 'com.microsoft.jdbc.sqlserver.SQLServerDriver',...
> > 'jdbc:microsoft:sqlserver://localhost:1433;database=testdb1')
> >
> > Which returns the message:
> >
> > JDBC Driver Error: com.microsoft.jdbc.sqlserver.SQLServerDriver. Driver Not Found/Loaded.
> >
> > Do I have to do something with the driver other than list it on the java class path?

I connect to MS SQL server 2008 from Matlab 2009a for Mac OS and it is fine:
javaaddpath('/Users/Documents/MATLAB/sqljdbc.jar');
conn = database('DataBase1','User','pass','com.microsoft.sqlserver.jdbc.SQLServerDriver','jdbc:sqlserver://192.168.1.1:1433;databaseName= DataBase1');
curs = exec(conn, 'select top 100 * from DataBase1.dbo.Table1');

Subject: SQL Server and JDBC drivers

From: Derek Jing

Date: 26 Oct, 2012 06:17:09

Message: 5 of 5

Below is a great tutorial that I found

http://quantlego.com/technote/connect-matlab-microsoft-sql-server-using-jdbc-driver

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us