将 Matlab 连接到 Sql 服务器 [英] Connect Matlab to Sql server

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

问题描述

我想把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:')

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	oolboxlocalclasspath.txt

更新后的路径条目现在应该包含驱动程序的完整路径.例如:

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

C:DB_Driverssqljdbc_2.0enusqljdbc4.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	oolboxlocallibrarypath.txt

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

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

C:DB_Driverssqljdbc_2.0enuauthx64

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 文件.

启动 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 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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