Matlab calls Oracle Database

Source: Internet
Author: User

This article is divided into two parts, 1, the operation of the database through SQL statements. 2. Working with databases through DDL

An ODBC-based connection to Oracle
1) Control Panel, management tool->ODBC data source, add Oracle Data source in System DSN;
2) in the MATLAB command line, enter the command to establish the connection:

CONN_ODBC = Database ('QUIK'QUIK'QUIK ') % Login Password

The second is to establish a connection to Oracle through JDBC, where I use the JDBC operation.
1) Locate the JDBC driver file D:\oracle_app\lcm\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar and copy it to

The Java subdirectory of the MATLAB installation directory D:\Program Files\matlab\r2013a\java\jar\toolbox;
2) Modify the MATLAB classpath file: D:\Program files\matlab\r2013a\toolbox\local\classpath.txt, add one at the end

Line content:

$matlabroot/java/jar/toolbox/ojdbc6.jar

3) in the MATLAB command line, enter the command to establish the connection:

CONN_JDBC = Database ('QUIK'QUIK'QUIK ' ' Oracle.jdbc.driver.OracleDriver ' ' Jdbc:oracle:thin: @localhost: 1521: ') % connection string

To view the connection status by using the ping command:

Ping (conn_odbc) ping (CONN_JDBC)

1, the database actual query operation 
Percent Read data fromOracle% Create a connection fromMatlab to Oracle%Oracle DataBase Connection Usage% conn = Database ('DBname','UserName','userpwd','Oracle.jdbc.driver.OracleDriver','Jdbc:oracle:thin: @localhost: 1521:');% conn = Database ('AVM','m','m','Oracle.jdbc.driver.OracleDriver','jdbc:oracle:thin:@10.84.13.18:1521:');% Execute Query andGetData fromoraclecurs= EXEC (conn,'SELECT * from Mes_imp_operate_log D');d ATA=fetch (curs);% Get Number fromOracledata=data. Data; %Last close CursorClose (curs); Close (conn);d ATA

The result output (as in the actual result, the result stores a similar matrix):

2. We perform an Insert DDL test:

Percent Read data fromOracle% Create a connection fromMatlab to Oracle%Oracle DataBase Connection Usage% conn = Database ('DBname','UserName','userpwd','Oracle.jdbc.driver.OracleDriver','Jdbc:oracle:thin: @localhost: 1521:');%Service Name Remember if Oracle is in action, it may not be a conn of TNS configuration= Database ('A','MSSD','MIS','Oracle.jdbc.driver.OracleDriver','jdbc:oracle:thin:@10.80.10.13:1521:'); % Execute Query andGetData fromOraclesql='INSERT into Mes_imp_operate_log (ID, create_time, user_id, Operate_type, remark, trace_no) VALUES (mes_imp_operate_ Log_s.nextval, Sysdate, 3,"'SS"', "'Input Test"', "'Test"' )'; Curs1=EXEC (conn, SQL);%Commit Or roolback transction%exec (CONN_ODBC,'rollback'); EXEC (Conn,'Commit'); Curs= EXEC (conn,'SELECT * from Mes_imp_operate_log');d ATA=fetch (curs);% Get Number fromOracledata=data. Data;%Last close CursorClose (curs); close (conn);
Test Results:

Java program calls Matlab, the. m file is packaged into a jar,eclipse call, you can refer to: http://www.myexception.cn/database/2074301.html Thank you for reading! Sharing is a virtue! Share Progress!

Matlab calls Oracle Database

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.