Connect Matlab to Sql server

。_饼干妹妹 提交于 2020-01-01 07:18:25

问题


I want to connect Matlab to Sql server.

this is my code:

db = database('ChifcoProd-2013-12-12-11-37', '', '', 'sqljdbc4.jar',...
'jdbc:microsoft:sqlserver://localhost:1433;database=ChifcoProd-2013-12-12-11-37')

error:

JDBC Driver Error: sqljdbc4.jar. Driver Not Found/Loaded

the driver is already installed and I added the path to javaclasspath but it doesn't work.


回答1:


Try using the Help within MatLab, its very helpful.

You are using the correct database connection:

conn = database(instance,username,password,driver,databaseurl)

The example provided by MatLab looks like this: Connect to an Oracle database via JDBC driver.

Connect to the database, test_db, using the user name, scott, and password, tiger. Use the JDBC driver, oracle.jdbc.driver.OracleDriver, to make the connection. The URL defined by the driver vendor is jdbc:oracle:oci7:

conn = database('test_db','scott','tiger',...
          'oracle.jdbc.driver.OracleDriver','jdbc:oracle:oci7:')

OR

Microsoft SQL Server Authenticated Database Connection

Connect to a Microsoft SQL Server database with integrated Windows Authentication using a JDBC driver.

Close MATLAB if it is running.

Insert the path to the database driver JAR file in the classpath.txt file. The classpath.txt file is located at:

$MATLABROOT\toolbox\local\classpath.txt

The updated path entry should now include the full path to the driver. For example:

C:\DB_Drivers\sqljdbc_2.0\enu\sqljdbc4.jar

Insert the path to the folder containing sqljdbc_auth.dll in the librarypath.txt file. The librarypath.txt file is located at:

$MATLABROOT\toolbox\local\librarypath.txt

The path entry should not include the file name sqljdbc_auth.dll:

C:\DB_Drivers\sqljdbc_2.0\enu\auth\x64

The sqljdbc_auth.dll file is installed in the following location:

<installation>\sqljdbc_<version>\<language>\auth\<arch>

where is the installation directory of the SQL server driver.

  • If you are running a 32-bit Java Virtual Machine (JVM), then use the sqljdbc_auth.dll file in the x86 folder, even if the operating system is the x64 version.
  • If you are running a 64-bit JVM on a x64 processor, then use the sqljdbc_auth.dll file in the x64 folder.
  • If you are running a 64-bit JVM on a IA-64 processor, then use the sqljdbc_auth.dll file in the IA64 folder.

Start MATLAB.

Use the AuthType parameter to establish a Windows Authentication connection.

conn = database('dbName','','', ...
   'Vendor','Microsoft SQL Server','Server','servername',...
   'AuthType','Windows')


来源:https://stackoverflow.com/questions/23469973/connect-matlab-to-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!