mercoledì 23 febbraio 2011

Connect from (Matlab on) MACOSX to Microsoft SQL Server (2005 Express)???

OK, that's a bit malad.
We have two ways: ODBC (proprietary, I downloaded OpenLink ODBC Adminstrator, with 30days trial), easily configurable, or JDBC (needed if you're using, for instance, Matlab for MacOS/Linux).
About JDBC, this link (http://www.razorsql.com/articles/sql_server_mac.html) says that we can have the JDBC driver in two ways:
The easiest way to connect to MS SQL Server from Mac is with a JDBC (Java Database Connectivity) driver. Since Mac OS X comes with Java pre-installed, the only thing that needs to be downloaded is a suitable JDBC driver. There are two options for JDBC driver. Once is the open source jTDS driver. The other is the JDBC driver from Microsoft.
About the JDBC driver from Microsoft, I'm not able to understand how to install it... and to use it...
About the iTDS driver, I downloaded it, but it comes like the Microsoft driver: basically a .jar file.

What to do?

I found it! ;)
JDBC is not like ODBC connection. ODBC is Microsoft-proprietary, and need some "tool" (like the one from OpenLink) to interact with the OS. JDBC, on the contrary, needs only an application to call the jar file, and so the libraries in it.

My problem was to connect to a Microsoft SQL Server 2005 with Matlab for MacOSX.
Matlab come with the Database Toolbox, and reading the help (...carefully reading...), I learned something. Matlab can use ODBC on Windows systems, and ODBC/JDBC on other systems. So, as we are in MacOSX, we are going to use a JDBC, previously downloaded (done!).
Now, guess wath? As Matlab is an application, and it's developed in Java too (and comes with his Java VM!!!), it's only necessary to understand where to indicate to Matlab the path of the JDBC jar-file.

I found this:
Specify the location of the drivers file in the MATLAB Sun Java classpath by adding this file's path to the matlabroot/toolbox/local/classpath.txt file.

I found it in /Applications/MATLAB_R2009b.app/toolbox/local/ , and I add the path "/Users/ivanoirrera/lib/MSSQL_JDBC/sqljdbc.jar" (in my case, but you can put the jar-library everywhere you want). Then restart Matlab.
After it, run "querybuilder", and click Query > Define JDBC Data Source.

Now, specify correctly the information the connection needs.
In my case:

name = master
driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
URL = //10.3.1.200:1433/master

Note: the Java version used by Matlab is 1.6, and Microsoft JDBC drivers 2.0 do not support this version! To solve the problem, download the "Microsoft SQL Server 2005 JDBC Driver 1.2" version.

Anyway... now it shows no problem... but it blocks :(

(to be completed)

Nessun commento: