将Matlab连接到Sql Server [英] Connect Matlab to Sql server

查看:332
本文介绍了将Matlab连接到Sql Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将Matlab连接到Sql server.

这是我的代码:

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

错误:

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

该驱动程序已经安装,我将路径添加到javaclasspath,但是它不起作用.

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

推荐答案

尝试在MatLab中使用帮助",它非常有用.

Try using the Help within MatLab, its very helpful.

您使用的是正确的数据库连接:

You are using the correct database connection:

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

MatLab提供的示例如下所示: 通过JDBC驱动程序连接到Oracle数据库.

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

使用用户名scott和密码tiger连接到test_db数据库.使用JDBC驱动程序oracle.jdbc.driver.OracleDriver建立连接.驱动程序供应商定义的URL是jdbc:oracle:oci7:

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身份验证的数据库连接

Microsoft SQL Server Authenticated Database Connection

使用JDBC驱动程序连接到具有集成Windows身份验证的Microsoft SQL Server数据库.

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

如果MATLAB正在运行,请关闭它.

Close MATLAB if it is running.

在classpath.txt文件中插入数据库驱动程序JAR文件的路径. classpath.txt文件位于:

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

将路径插入到librarypath.txt文件中包含sqljdbc_auth.dll的文件夹中. librarypath.txt文件位于:

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

路径条目中不应包含文件名sqljdbc_auth.dll:

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

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

sqljdbc_auth.dll文件安装在以下位置:

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

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

SQL Server驱动程序的安装目录在哪里.

where is the installation directory of the SQL server driver.

  • 如果您正在运行32位Java虚拟机(JVM),请使用 即使在操作系统中,x86文件夹中的sqljdbc_auth.dll文件 是x64版本.
  • 如果您在x64处理器上运行64位JVM,请使用 x64文件夹中的sqljdbc_auth.dll文件.
  • 如果您正在IA-64处理器上运行64位JVM,请使用 IA64文件夹中的sqljdbc_auth.dll文件.
  • 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.

启动MATLAB.

使用AuthType参数建立Windows身份验证连接.

Use the AuthType parameter to establish a Windows Authentication connection.

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

这篇关于将Matlab连接到Sql Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆