View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
MS SQL JDBC connection

Be the first to rate this file! 13 Downloads (last 30 days) File Size: 3.22 KB File ID: #25577 Version: 1.6
image thumbnail

MS SQL JDBC connection


Oleg Komarov (view profile)


14 Oct 2009 (Updated )

Establishes JDBC connection to MS SQL Easier to use than "database(…)" NEW! Windows authentication

| Watch this File

File Information

MSSQLconn establishes a JDBC connection with MS SQL.
This function handles better the inputs and the error msgs than the database function.

   - dbname: database name to which you want to connect (char format)
   - userpassmethod --> {'username','password'}; 1st cell username,2nd cell password
   - userpassmethod --> '-win'; use windows authentication (only for R2008b)
   - userpassmethod --> '-manual'; supply credentials through inputdlg
   - servername: string with the server where the database is hosted
   - portnumber: integer of the port
   - oldversion: if MS SQL is older than 2005 ed. supply '-old';
Only dbname is mandatory. Only one method to supply username and password is accepted at one time. Optionals can be supplied in any order and combination.

   - Class 'database': connection to the server.
   - Class 'structure' with the settings used to connect (except password).

   - user = '';
   - pass = '';
   - server = 'localhost';
   - port = 1433;
   - driver = '' (MS SQL 2005 and above);
   - windows authentication: false;

   - MSSQLconn('MyDB') % use the whole set of default settings
   - MSSQLconn('MyDB',{'Oleg','****'}) % supply username and password
   - MSSQLconn('MyDB',{'Oleg',''}) % supply just the username, password by inputdlg
   - MSSQLconn('MyDB','-win') % use windows authentication
   - MSSQLconn('MyDB','-manual') % supply both username and password through inputdlg
   - MSSQLconn(...,'myserver') % supply servername with any combination of dbname and userpassmethod
   - MSSQLconn(...,1433, 'myserver','-old') % full set of optionals
Installing the driver:
1) If you don't have the drivers package download it from:
   This page explains which driver fits your case.
2) Add the path of the .jar driver manually (better) to:
3) Check with "javaclasspath" (cmd pane) if the driver has been added correctly.
4) To be able to use windows credentials with '-win' userpassmethod, add just the directory where the .dll is to:
    The .dll is contained in the JDBC driver package. For more details:

Comments/suggestions/error reports are welcome.

If other DBMS connection are required, plz write at


Required Products Database Toolbox
MATLAB release MATLAB 7.9 (R2009b)
Other requirements Tested on 2009b with MS SQL 2008
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
19 Oct 2010 Oleg Komarov

Oleg Komarov (view profile)

It is essentially a MSSQL wrapper of the database function from the Database TB.
So in order to have it working you should have the proper java drivers (read above) and the Database TB.

Comment only
19 Oct 2010 Robin den Dekker

I accidently pushed the rating but couldn't change it. Im sorry for that. This file will make a connection between Matlab and MSSQL possible and works aswell?

Comment only
09 Nov 2009 Oleg Komarov

Oleg Komarov (view profile)

Testing additional feature to use Windows Authentication login.

Comment only
14 Oct 2009 1.1

Edited description; added link to FEX MSSQLconn in the help part of the function

27 Oct 2009 1.4

Added: single input syntax and screenshot. Edited description.

28 Oct 2009 1.5

Corrected some minor bugs and reorganized some code.

10 Nov 2009 1.6

Added windows authentication feature, changed syntax and edited description.

Contact us