MATLAB Data link and query

Source: Internet
Author: User

Objective

In the previous article, we talked about linking databases from the database Toolbox. In Matlab, you can also use the Visual Tools database Toolbox to perform some SQL operations. However, for database programming, you do not want to manually open the visualizer when executing the script, so you need to link and execute the SQL command on the command line.

Content Summary

This article mainly describes

    1. Connect to the database on the command line
    2. Execute SQL statement
    3. Storing results to an object
    4. Output data
Specific operation
    • Connecting to a database

The main use of this article is the MySQL database, the connection using the JDBC driver (driver introduction, download and installation see MATLAB link MySQL method). If you need to use an ODBC connection, the approximate process is basically the same, the details of the official documents and other information are not discussed here.

Database links, you first need to write the statements used by the link. First, the role of the link statement and write an example:

conn = Database (Instance,username,password,driver,databaseurl)

The above statement describes the writing requirements of the LINK statement: Conn is the return of the linked object, database is the function used in MATLAB to link the databases, the instance parameter is the data name that you need to link MySQL, username is the link mysql user name, Password is the user name username corresponding password, dirver is the database (used in this article is MySQL) and matlab driver, databaseurl description see matlab link MySQL method. For such criteria, this paper gives an example of the actual use of the author, for reference: conn=database (' Test ', ' root ', ', ' Mysql_connector_java_5.1.35_bin.jar ', ' jdbc:mysql:// Localhost:3306/test ')

Then use the EXEC function to execute the above linked statement: EXEC (conn, ' SQLQuery ')

    • Execute SQL statement
After the linked database succeeds, prepare the relevant SQL statement and execute the

UID=EXEC (conn, ' Select UID form user ');

Uid=fetch (UID);

NOTE: Here the SQL statement execution is divided into: Execute SQL file and execute SQL statement directly two kinds. As for the specific execution of the SQL file operation details here are not elaborated.

    • Storing results to an object
After executing the SQL statement described above, the query results need to be processed:
Uiddata=uid.data;
    • Output data

Enter Uiddata to get the desired result information.

The above represents only personal views, if there are errors please correct me.

MATLAB data links and queries

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.