DB Toolbox连接Matlab和常用的数据库
利用MATLAB进行数据库连接和操作

利用MATLAB进行数据库连接和操作引言随着信息技术的飞速发展,数据库的使用在各个领域中变得越来越重要。
而MATLAB作为一种功能强大的数值计算和数据分析工具,提供了方便的数据库连接和操作功能。
本文将介绍如何利用MATLAB进行数据库连接和操作,以及一些常见的应用场景。
一、数据库连接在使用MATLAB进行数据库操作之前,首先需要进行数据库连接。
MATLAB 中可以通过调用数据库驱动程序实现与各种类型的数据库的连接。
1. JDBC连接JDBC(Java Database Connectivity)是一种用于执行SQL语句的Java API。
在MATLAB中,我们可以使用JDBC来实现与支持JDBC连接的数据库的通信。
首先,我们需要下载适当的JDBC驱动程序,并将其添加到MATLAB的Java类路径中。
之后,我们可以使用MATLAB提供的“database”函数来实现数据库的连接。
例如,我们可以使用如下的代码来连接一个MySQL数据库:```matlaburl = 'jdbc:mysql://localhost:3306/database_name';username = 'username';password = 'password';conn = database(url, username, password);```2. ODBC连接ODBC(Open Database Connectivity)是一种用于连接各种类型的数据库的标准接口。
在MATLAB中,我们可以通过ODBC来连接支持ODBC连接的数据库。
首先,我们需要在系统中配置好ODBC数据源。
之后,我们可以使用MATLAB提供的“odbc”函数来实现数据库的连接。
例如,我们可以使用如下的代码来连接一个MS Access数据库:```matlabdatasource = 'Microsoft Access Driver (*.mdb, *.accdb)';databasefile = 'C:\path\to\database.accdb';username = 'username';password = 'password';conn = odbc(datasource, username, password, 'db_file', databasefile);```二、数据库操作数据库连接成功后,我们就可以利用MATLAB进行各种数据库操作了。
MATLAB和数据库的连接

由于M atlab 不同于其它编程语言, 因 此在使用数据库方面和其它语言有显著不
若要对数据操作, 则先要获取指针。 权限, 其次为D efau lt 项权限。例如: U ser01
exec (connection, sqlQ uery)
在数据库的 A CL 表中是作者权限, 则用户
据库文件应调用哪一个驱动程序。
通 过 database 语 句 获 得 数 据 库 的 句 数据的输入输出方式非常方便。
要与数据库连接, 首先需要有一个环 柄, 它返回一个连接结构给 connection。
境, 它建立程序和 ODBC 之间的联系, 应用
其 中: IN STAN CE 是 数 据 库 名,
ODBC 是一个基于 DLL 的结构, 它的 3 M a tlab 与数据库的连接
row s 等, 运用这些函数可以方便的对数据 库进行操作。
4 实 例
例程用 M atlab 的 M 文件建立, 详细 说明了如何在M atlab 中调用数据库, 并且 实现对数据库的操作。
connection= database (’sam p le’,‘’,‘’) ; 建 立连接
cc= {m ean}; in sert (connection, ’db’, ’c’, cc) ; 将结果插 入数据库
所 有 驱 动 器 都 是 用 DLL 方 式。 对 于
M atlab 对数据库的操作, 一般是先获
clo se (cu rso rl) ; 关闭指针
DBM S, 只要提供了该数据库管理系统的 得数据库的句柄, 然后用M atlab 函数进行
均在M atlab 的命令窗。 ● 对单个数据库可以使用多个指针。
matlab与数据库链接

matlab与数据库链接一、Matlab与数据库链接1 配置数据源控制面板--管理工具—数据源(ODBC)--添加—创建数据源名称和选择数据库文件。
2 建立链接对象—databaseconna = database(‘datasoursename’,’username’,’password’);conna = database(‘D5000’,’sa’,’123’) conna = database(‘D5000’,’’,’‘);输入参数:databasename:数据库名称(若不是本地数据,需输入网址或IP地址及端口。
username:数据库用户名password:数据库密码输出参数:conna建立数据链接对象(参数AutoCommit,on表示数据库链接成功,off表示数据库链接失败。
获取数据库连接信息函数:ping(conna)3 建立并打开游标—execcurs = exec(conna,’sqlquery’)输入参数:conna数据库链接对象,sqlquery sql数据库查询语句输出参数:curs 结构体游标curs = exec(connna,’select all price from stock.dbo.hs30 where data berween’’2008’‘and’‘2008’’4 把数据库中的数据读取到matlab中—fetchcurs = fetch(curs,rowlimit) curs = fetch(curs) 全部读取输入参数:rowlimit为每次读取的数据参数的行数5 关闭数据库链接close(curs):关闭查询游标close(conna):关闭数据链接目的:及时释放内存7 其他应用函数数据库游标访问函数数据库元数据函数二、把数据写入数据库1 添加数据到表中—insert函数1)插入单行数据insert(conna,’tab’,colnames,exdata)fastinsert(conna,’tab’,colnames,exdata)conna:链接对象tab:数据库文件的表名colnames:数据库表的列明exdata:matlab变量insert(conna,’try’,{‘a1’,’a2’},[45 65])commit(conna) 确认数据更改2)插入多行数据load hs30N = length(hs30Price)for i = 1 : NexpData = {hs30Data(i),hs30Price(i),hs30Vol(i)};fastinsert(conna,’StockData.dbo.Hs30’,{‘Data’;’Price’;’V ol’},expData)‘endclose(conna);2 更新数据库中的数据—updateupdate(conna,’tab’,colnames,exdata,’whereclause’)conna:链接对象;tab:数据库文件的表名;colnames:数据库表的列名exdata:matlab变量;whereclause:SQL的where子句update(conna,’try’,{‘a1’;’a2’},[45;65],’wherexx=’xx’)3 建立新表—exec,create tableconna = database(‘samleDB’,’‘, ‘‘)exec(conna,[‘create table Table(name string,age int)’]);4 把数据写入到数据库文件中data = rand(100,100);data = fix(10000 * data)/10000; % 减少data的有效位dlmwrite(‘data.txt’,data,’delimiter’,’‘ ,’newline’,’p c’);。
最完整的MATLAB工具箱的链接

MATLAB Toolboxestop Audio - Astronomy - BioMedicalInformatics - Chemometrics - Chaos - Chemistry - Coding - Control - Communications - Engineering - Excel - FEM - Finance - GAs - Graphics - Images - ICA - Kernel - Markov - Medical - MIDI - Misc. - MPI - NNets - Oceanography - Optimization - Plot - Signal Processing - Optimization - Statistics - SVM - etc ...NewZSM (zero sum multinomial)/zsmcode.htmlBinaural-modeling software for MATLAB/Windows/home/Michael_Akeroyd/download2.ht mlStatistical Parametric Mapping (SPM)/spm/ext/BOOTSTRAP MATLAB TOOLBOX.au/downloads/bootstrap_toolbox.htmlThe DSS package for MATLABDSS Matlab package contains algorithms for performing linear, deflation and symmetric DSS.http://www.cis.hut.fi/projects/dss/package/Psychtoolbox/download.htmlMultisurface Method Tree with MATLAB/~olvi/uwmp/msmt.htmlA Matlab Toolbox for every single topic !/~baum/toolboxes.htmleg. BrainStorm - MEG and EEG data visualization and processing CLAWPACK is a software package designed to compute numerical solutionsto hyperbolic partial differential equations using a wave propagation approach/~claw/DIPimage - Image Processing ToolboxPRTools - Pattern Recognition Toolbox (+ Neural Networks)NetLab - Neural Network ToolboxFSTB - Fuzzy Systems ToolboxFusetool - Image Fusion Toolboxhttp://www.metapix.de/toolbox.htmWAVEKIT - Wavelet ToolboxGat - Genetic Algorithm ToolboxTSTOOL is a MATLAB software package for nonlinear time series analysis. TSTOOL can be used for computing: Time-delay reconstruction, Lyapunov exponents, Fractal dimensions, Mutual information, Surrogate data tests, Nearest neighbor statistics, Return times, Poincare sections, Nonlinear predictionhttp://www.physik3.gwdg.de/tstool/MATLAB / Data description toolboxA Matlab toolbox for data description, outlier and novelty detection March 26, 2004 - D.M.J. Taxhttp://www-ict.ewi.tudelft.nl/~davidt/dd_tools/dd_manual.htmlMBEhttp://www.pmarneffei.hku.hk/mbetoolbox/Betabolic network toolbox for Matlabhttp://www.molgen.mpg.de/~lieberme/pages/network_matlab.htmlPharmacokinetics toolbox for Matlabhttp://page.inf.fu-berlin.de/~lieber/seiten/pbpk_toolbox.htmlThe SpiderThe spider is intended to be a complete object orientated environment for machine learning in Matlab. Aside from easy use of base learning algorithms, algorithms can be plugged together and can be comparedwith, e.g model selection, statistical tests and visual plots. This gives all the power of objects (reusability, plug together, share code) but also all the power of Matlab for machine learning research. http://www.kyb.tuebingen.mpg.de/bs/people/spider/index.htmlSchwarz-Christoffel Toolbox/matlabcentral/fileexchange/loadFile.do?o bjectId=1316&objectType=file#XML Toolbox/matlabcentral/fileexchange/loadFile.do?o bjectId=4278&objectType=fileFIR/TDNN Toolbox for MATLABBeta version of a toolbox for FIR (Finite Impulse Response) and TD (Time Delay) Neural Networks./interval-comp/dagstuhl.03/oish.pdfMisc.http://www.dcsc.tudelft.nl/Research/Software/index.htmlAstronomySaturn and Titan trajectories ... MALTAB astronomy/~abrecht/Matlab-codes/AudioMA Toolbox for Matlab Implementing Similarity Measures for Audio http://www.oefai.at/~elias/ma/index.htmlMAD - Matlab Auditory Demonstrations/~martin/MAD/docs/mad.htmMusic Analysis - Toolbox for Matlab : Feature Extraction from Raw Audio Signals for Content-Based Music Retrievalhttp://www.ai.univie.ac.at/~elias/ma/WarpTB - Matlab Toolbox for Warped DSPBy Aki Härmä and Matti Karjalainenhttp://www.acoustics.hut.fi/software/warp/MATLAB-related Softwarehttp://www.dpmi.tu-graz.ac.at/~schloegl/matlab/Biomedical Signal data formats (EEG machine specific file formats with Matlab import routines)http://www.dpmi.tu-graz.ac.at/~schloegl/matlab/eeg/MPEG Encoding library for MATLAB Movies (Created by David Foti)It enables MATLAB users to read (MPGREAD) or write (MPGWRITE) MPEG movies. That should help Video Quality project.Filter Design packagehttp://www.ee.ryerson.ca:8080/~mzeytin/dfp/index.htmlOctave by Christophe COUVREUR (Generates normalized A-weigthing, C-weighting, octave and one-third-octave digital filters)/matlabcentral/fileexchange/loadFile.do?o bjectType=file&objectId=69Source Coding MATLAB Toolbox/users/kieffer/programs.htmlBio Medical Informatics (Top)CGH-Plotter: MATLAB Toolbox for CGH-data AnalysisCode: http://sigwww.cs.tut.fi/TICSP/CGH-Plotter/Poster:http://sigwww.cs.tut.fi/TICSP/CSB2003/Posteri_CGH_Plotter.pdfThe Brain Imaging Software Toolboxhttp://www.bic.mni.mcgill.ca/software/MRI Brain Segmentation/matlabcentral/fileexchange/loadFile.do?o bjectId=4879Chemometrics (providing PCA) (Top)Matlab Molecular Biology & Evolution Toolbox(Toolbox Enables Evolutionary Biologists to Analyze and View DNA and Protein Sequences)James J. Caihttp://www.pmarneffei.hku.hk/mbetoolbox/Toolbox provided by Prof. Massart research grouphttp://minf.vub.ac.be/~fabi/publiek/Useful collection of routines from Prof age smilde research group http://www-its.chem.uva.nl/research/pacMultivariate Toolbox written by Rune Mathisen/~mvartools/index.htmlMatlab code and datasetshttp://www.acc.umu.se/~tnkjtg/chemometrics/dataset.htmlChaos (Top)Chaotic Systems Toolbox/matlabcentral/fileexchange/loadFile.do?o bjectId=1597&objectType=file#HOSA Toolboxhttp://www.mathworks.nl/matlabcentral/fileexchange/loadFile.do?ob jectId=3013&objectType=fileChemistry (Top)MetMAP - (Metabolical Modeling, Analysis and oPtimization alias Met. M. A. P.)http://webpages.ull.es/users/sympbst/pag_ing/pag_metmap/index.htmDoseLab - A set of software programs for quantitative comparison of measured and computed radiation dose distributionsGenBank Overview/Genbank/GenbankOverview.htmlMatlab:/matlabcentral/fileexchange/loadFile.do?o bjectId=1139CodingCode for the estimation of Scaling Exponentshttp://www.cubinlab.ee.mu.oz.au/~darryl/secondorder_code.html Control (Top)Control Tutorial for Matlab/group/ctm/AnotherCommunications (Top)Channel Learning Architecture toolbox(This Matlab toolbox is a supplement to the article "HiperLearn: A High Performance Learning Architecture")http://www.isy.liu.se/cvl/Projects/hiperlearn/Source Coding MATLAB Toolbox/users/kieffer/programs.htmlTCP/UDP/IP Toolbox 2.0.4/matlabcentral/fileexchange/loadFile.do?o bjectId=345&objectType=fileHome Networking Basis: Transmission Environments and Wired/Wireless ProtocolsWalter Y. Chen/support/books/book5295.jsp?category=new& language=-1MATLAB M-files and Simulink models/matlabcentral/fileexchange/loadFile.do?o bjectId=3834&objectType=fileEngineering (Top)OPNML/MATLAB Facilities/OPNML_Matlab/Mesh Generation/home/vavasis/qmg-home.htmlOpenFEM : An Open-Source Finite Element Toolbox/CALFEM is an interactive computer program for teaching the finite element method (FEM)http://www.byggmek.lth.se/Calfem/frinfo.htmThe Engineering Vibration Toolbox/people/faculty/jslater/vtoolbox/vtoolbox .htmlSaGA - Spatial and Geometric Analysis Toolboxby Kirill K. Pankratov/~glenn/kirill/saga.htmlMexCDF and NetCDF Toolbox For Matlab-5&6/staffpages/cdenham/public_html/MexCDF/nc4ml5.htmlCUEDSID: Cambridge University System Identification Toolbox/jmm/cuedsid/Kriging Toolbox/software/Geostats_software/MATLAB_KRIG ING_TOOLBOX.htmMonte Carlo (Dr Nando)http://www.cs.ubc.ca/~nando/software.htmlRIOTS - The Most Powerful Optimal Control Problem Solver/~adam/RIOTS/ExcelMATLAB xlsheets/matlabcentral/fileexchange/loadFile.do?o bjectId=4474&objectType=filewrite2excel/matlabcentral/fileexchange/loadFile.do?o bjectId=4414&objectType=fileFinite Element Modeling (FEM) (Top)OpenFEM - An Open-Source Finite Element Toolbox/NLFET - nonlinear finite element toolbox for MATLAB ( framework for setting up, solving, and interpreting results for nonlinear static and dynamic finite element analysis.)/GetFEM - C++ library for finite element methods elementary computations with a Matlab interfacehttp://www.gmm.insa-tlse.fr/getfem/FELIPE - FEA package to view results ( contains neat interface to MATLA /~blstmbr/felipe/Finance (Top)A NEW MATLAB-BASED TOOLBOX FOR COMPUTER AIDED DYNAMIC TECHNICAL TRADING Stephanos Papadamou and George StephanidesDepartment of Applied Informatics, University Of Macedonia Economic & Social Sciences, Thessaloniki, Greece/fen31/one_time_articles/dynamic_tech_trade_ matlab6.htmPaper::8089/eps/prog/papers/0201/0201001.pdfCompEcon Toolbox for Matlab/~pfackler/compecon/toolbox.htmlGenetic Algorithms (Top)The Genetic Algorithm Optimization Toolbox (GAOT) for Matlab 5 /mirage/GAToolBox/gaot/Genetic Algorithm ToolboxWritten & distributed by Andy Chipperfield (Sheffield University, UK) /uni/projects/gaipp/gatbx.htmlManual: /~gaipp/ga-toolbox/manual.pdfGenetic and Evolutionary Algorithm Toolbox (GEATbx)Evolutionary Algorithms for MATLAB/links/ea_matlab.htmlGenetic/Evolutionary Algorithms for MATLABhttp://www.systemtechnik.tu-ilmenau.de/~pohlheim/EA_Matlab/ea_mat lab.htmlGraphicsVideoToolbox (C routines for visual psychophysics on Macs by Denis Pelli)/VideoToolbox/Paper: /pelli/pubs/pelli1997videotoolbox.pdf4D toolbox/~daniel/links/matlab/4DToolbox.htmlImages (Top)Eyelink Toolbox/eyelinktoolbox/Paper: /eyelinktoolbox/EyelinkToolbox.pdfCellStats: Automated statistical analysis of color-stained cell images in Matlabhttp://sigwww.cs.tut.fi/TICSP/CellStats/SDC Morphology Toolbox for MATLAB (powerful collection of latest state-of-the-art gray-scale morphological tools that can be applied to image segmentation, non-linear filtering, pattern recognition and image analysis)/Image Acquisition Toolbox/products/imaq/Halftoning Toolbox for MATLAB/~bevans/projects/halftoning/toolbox/ind ex.htmlDIPimage - A Scientific Image Processing Toolbox for MATLABhttp://www.ph.tn.tudelft.nl/DIPlib/dipimage_1.htmlPNM Toolboxhttp://home.online.no/~pjacklam/matlab/software/pnm/index.html AnotherICA / KICA and KPCA (Top)ICA TU Toolboxhttp://mole.imm.dtu.dk/toolbox/menu.htmlMISEP Linear and Nonlinear ICA Toolboxhttp://neural.inesc-id.pt/~lba/ica/mitoolbox.htmlKernel Independant Component Analysis/~fbach/kernel-ica/index.htmMatlab: kernel-ica version 1.2KPCA- Please check the software section of kernel machines.KernelStatistical Pattern Recognition Toolboxhttp://cmp.felk.cvut.cz/~xfrancv/stprtool/MATLABArsenal A MATLAB Wrapper for Classification/tmp/MATLABArsenal.htmMarkov (Top)MapHMMBOX 1.1 - Matlab toolbox for Hidden Markov Modelling using Max. Aposteriori EMPrerequisites: Matlab 5.0, Netlab. Last Updated: 18 March 2002. /~parg/software/maphmmbox_1_1.tarHMMBOX 4.1 - Matlab toolbox for Hidden Markov Modelling using Variational BayesPrerequisites: Matlab 5.0,Netlab. Last Updated: 15 February 2002.. /~parg/software/hmmbox_3_2.tar/~parg/software/hmmbox_4_1.tarMarkov Decision Process (MDP) Toolbox for MatlabKevin Murphy, 1999/~murphyk/Software/MDP/MDP.zipMarkov Decision Process (MDP) Toolbox v1.0 for MATLABhttp://www.inra.fr/bia/T/MDPtoolbox/Hidden Markov Model (HMM) Toolbox for Matlab/~murphyk/Software/HMM/hmm.htmlBayes Net Toolbox for Matlab/~murphyk/Software/BNT/bnt.htmlMedical (Top)EEGLAB Open Source Matlab Toolbox for Physiological Research (formerly ICA/EEG Matlab toolbox)/~scott/ica.htmlMATLAB Biomedical Signal Processing Toolbox/Toolbox/Powerful package for neurophysiological data analysis ( Igor Kagan webpage)/Matlab/Unitret.htmlEEG / MRI Matlab Toolbox/Microarray data analysis toolbox (MDAT): for normalization, adjustment and analysis of gene expression data.Knowlton N, Dozmorov IM, Centola M. Department of Arthritis andImmunology, Oklahoma Medical Research Foundation, Oklahoma City, OK, USA 73104. We introduce a novel Matlab toolbox for microarray data analysis. This toolbox uses normalization based upon a normally distributed background and differential gene expression based on 5 statistical measures. The objects in this toolbox are open source and can be implemented to suit your application. AVAILABILITY: MDAT v1.0 is a Matlab toolbox and requires Matlab to run. MDAT is freely available at:/publications/2004/knowlton/MDAT.zip MIDI (Top)MIDI Toolbox version 1.0 (GNU General Public License)http://www.jyu.fi/musica/miditoolbox/Misc. (Top)MATLAB-The Graphing Tool/~abrecht/matlab.html3-D Circuits The Circuit Animation Toolbox for MATLAB/other/3Dcircuits/SendMailhttp://carol.wins.uva.nl/~portegie/matlab/sendmail/Coolplothttp://www.reimeika.ca/marco/matlab/coolplots.htmlMPI (Matlab Parallel Interface)Cornell Multitask Toolbox for MATLAB/Services/Software/CMTM/Beolab Toolbox for v6.5Thomas Abrahamsson (Professor, Chalmers University of Technology, Applied Mechanics, Göteborg, Sweden)http://www.mathworks.nl/matlabcentral/fileexchange/loadFile.do?ob jectId=1216&objectType=filePARMATLABNeural Networks (Top)SOM Toolboxhttp://www.cis.hut.fi/projects/somtoolbox/Bayes Net Toolbox for Matlab/~murphyk/Software/BNT/bnt.htmlNetLab/netlab/Random Neural Networks/~ahossam/rnnsimv2/ftp: ftp:///pub/contrib/v5/nnet/rnnsimv2/NNSYSID Toolbox (tools for neural network based identification of nonlinear dynamic systems)http://www.iau.dtu.dk/research/control/nnsysid.htmlOceanography (Top)WAFO. Wave Analysis for Fatigue and Oceanographyhttp://www.maths.lth.se/matstat/wafo/ADCP toolbox for MATLAB (USGS, USA)Presented at the Hydroacoustics Workshop in Tampa and at ADCP's in Action in San Diego/operations/stg/pubs/ADCPtoolsSEA-MAT - Matlab Tools for Oceanographic AnalysisA collaborative effort to organize and distribute Matlab tools for the Oceanographic Community/Ocean Toolboxhttp://www.mar.dfo-mpo.gc.ca/science/ocean/epsonde/programming.htmlEUGENE D. GALLAGHER(Associate Professor, Environmental, Coastal & Ocean Sciences) /edgwebp.htmOptimization (Top)MODCONS - a MATLAB Toolbox for Multi-Objective Control System Design /mecheng/jfw/modcons.htmlLazy Learning Packagehttp://iridia.ulb.ac.be/~lazy/SDPT3 version 3.02 -- a MATLAB software for semidefinite-quadratic-linear programming.sg/~mattohkc/sdpt3.htmlMinimum Enclosing Balls: Matlab Code/meb/SOSTOOLS Sum of Squares Optimization Toolbox for MATLAB User’s guide /sostools/sostools.pdfPSOt - a Particle Swarm Optimization Toolbox for use with MatlabBy Brian Birge ... A Particle Swarm Optimization Toolbox (PSOt) for use with the Matlab scientific programming environment has been developed. PSO isintroduced briefly and then the use of the toolbox is explained with some examples. A link to downloadable code is provided.Plot/software/plotting/gbplot/Signal Processing (Top)Filter Design with Motorola DSP56Khttp://www.ee.ryerson.ca:8080/~mzeytin/dfp/index.htmlChange Detection and Adaptive Filtering Toolboxhttp://www.sigmoid.se/Signal Processing Toolbox/products/signal/ICA TU Toolboxhttp://mole.imm.dtu.dk/toolbox/menu.htmlTime-Frequency Toolbox for Matlabhttp://crttsn.univ-nantes.fr/~auger/tftb.htmlVoiceBox - Speech Processing Toolbox/hp/staff/dmb/voicebox/voicebox.htmlLeast Squared - Support Vector Machines (LS-SVM)http://www.esat.kuleuven.ac.be/sista/lssvmlab/WaveLab802 : the Wavelet ToolboxBy David Donoho, Mark Reynold Duncan, Xiaoming Huo, Ofer Levi /~wavelab/Time-series Matlab scriptshttp://wise-obs.tau.ac.il/~eran/MATLAB/TimeseriesCon.htmlUvi_Wave Wavelet Toolbox Home Pagehttp://www.gts.tsc.uvigo.es/~wavelets/index.htmlAnotherSupport Vector Machine (Top)MATLAB Support Vector Machine ToolboxDr Gavin CawleySchool of Information Systems, University of East Anglia/~gcc/svm/toolbox/LS-SVM - SISTASVM toolboxes/dmi/svm/LSVM Lagrangian Support Vector Machine/dmi/lsvm/Statistics (Top)Logistic regression/SAGA/software/saga/Multi-Parametric Toolbox (MPT) A tool (not only) for multi-parametric optimization.http://control.ee.ethz.ch/~mpt/ARfit: A Matlab package for the estimation of parameters and eigenmodes of multivariate autoregressive modelshttp://www.mat.univie.ac.at/~neum/software/arfit/The Dimensional Analysis Toolbox for MATLABHome: http://www.sbrs.de/Paper:http://www.isd.uni-stuttgart.de/~brueckner/Papers/similarity2002. pdfFATHOM for Matlab/personal/djones/PLS-toolboxMultivariate analysis toolbox (N-way Toolbox - paper)http://www.models.kvl.dk/source/nwaytoolbox/index.aspClassification Toolbox for Matlabhttp://tiger.technion.ac.il/~eladyt/classification/index.htmMatlab toolbox for Robust Calibrationhttp://www.wis.kuleuven.ac.be/stat/robust/toolbox.htmlStatistical Parametric Mapping/spm/spm2.htmlEVIM: A Software Package for Extreme Value Analysis in Matlabby Ramazan Gençay, Faruk Selcuk and Abdurrahman Ulugulyagci, 2001. Manual (pdf file) evim.pdf - Software (zip file) evim.zipTime Series Analysishttp://www.dpmi.tu-graz.ac.at/~schloegl/matlab/tsa/Bayes Net Toolbox for MatlabWritten by Kevin Murphy/~murphyk/Software/BNT/bnt.htmlOther: /information/toolboxes.htmlARfit: A Matlab package for the estimation of parameters and eigenmodes of multivariate autoregressive models/~tapio/arfit/M-Fithttp://www.ill.fr/tas/matlab/doc/mfit4/mfit.htmlDimensional Analysis Toolbox for Matlab/The NaN-toolbox: A statistic-toolbox for Octave and Matlab® ... handles data with and without MISSING VALUES.http://www-dpmi.tu-graz.ac.at/~schloegl/matlab/NaN/Iterative Methods for Optimization: Matlab Codes/~ctk/matlab_darts.htmlMultiscale Shape Analysis (MSA) Matlab Toolbox 2000p.br/~cesar/projects/multiscale/Multivariate Ecological & Oceanographic Data Analysis (FATHOM) From David Jones/personal/djones/glmlab (Generalized Linear Models in MATLA.au/staff/dunn/glmlab/glmlab.html Spacial and Geometric Analysis (SaGA) toolboxInteresting audio links with FAQ, VC++, on the topicMATLAB Toolboxes(C) 2004 - SPMC / SoCCE / UoP。
MATLAB与外部软件集成技术

MATLAB与外部软件集成技术概述:MATLAB是一种广泛应用于科学计算、数据分析和工程模拟的高级编程语言和环境。
然而,在现实世界的复杂问题中,MATLAB作为一个独立的软件工具并不能解决所有的需求。
幸运的是,MATLAB提供了与各种外部软件集成的能力,使用户能够更好地扩展其功能和应用领域。
本文将深入讨论MATLAB与外部软件集成的技术和方法,并探讨一些实际案例。
1. MATLAB与C/C++集成:在某些情况下,由于性能或者遗留代码的原因,使用MATLAB作为纯粹的数值计算环境可能不够高效。
但是,使用MATLAB的MEX接口,用户可以通过编写C/C++代码来扩展MATLAB的功能。
通过使用MEX接口,用户可以将C/C++代码编译为MATLAB可以直接调用的可执行文件,实现高性能的数值计算和算法加速。
2. MATLAB与Python集成:Python是一种强大的通用编程语言,其拥有丰富的第三方库和工具。
与MATLAB相比,Python在许多领域都具有自己独特的优势。
为了更好地利用两者的优点,用户可以使用MATLAB的Python引擎来实现它们之间的集成。
通过Python引擎,用户可以在MATLAB中直接调用Python代码,并将其结果作为MATLAB变量进行后续处理和分析。
这种集成使得用户可以利用Python的数据科学、机器学习和深度学习库,以及MATLAB在算法优化和可视化方面的强大功能。
3. MATLAB与数据库集成:在实际应用中,数据通常存储在数据库中,而不是保存在MATLAB的工作空间中。
为了更方便地处理和分析数据库中的数据,MATLAB提供了与多种关系型数据库的集成能力。
用户可以使用MATLAB的Database Toolbox来连接和查询数据库,从而直接在MATLAB中进行数据分析和处理。
这种集成能力对于需要从大型数据源中提取、筛选和分析数据的任务非常有用,例如金融数据分析、传感器数据处理等。
matlab数据库编程

在MATLAB中,可以使用内置的Database Toolbox进行数据库编程。
以下是一些基本步骤,以帮助您开始使用MATLAB进行数据库编程。
1. 连接到数据库使用Database Toolbox提供的函数,可以连接到各种类型的数据库,例如MySQL、Oracle、SQL Server等。
例如,要连接到MySQL 数据库,可以使用以下代码:```matlabconn = database('username','password','database_name','host_name','port');```其中,username和password是数据库的用户名和密码,database_name是数据库的名称,host_name是数据库的主机名,port 是数据库的端口号。
2. 执行SQL查询连接到数据库后,可以使用SQL查询语句执行各种操作,例如SELECT、INSERT、UPDATE、DELETE等。
例如,要查询一个名为table_name的表中的所有数据,可以使用以下代码:```matlabsql_query = 'SELECT * FROM table_name';result = exec(conn, sql_query);```其中,exec函数执行SQL查询并返回结果。
3. 处理查询结果查询结果可以以表格或元数据的形式返回。
可以使用MATLAB 内置的函数处理查询结果,例如将结果保存到变量中、显示结果等。
例如,要将查询结果保存到名为result的变量中,可以使用以下代码:```matlabresult = fetch(result);```其中,fetch函数将查询结果保存到变量中。
4. 关闭连接在完成所有操作后,应该关闭与数据库的连接。
可以使用close 函数关闭连接,例如:```matlabclose(conn);```以上是MATLAB数据库编程的基本步骤。
DBToolbox连接Matlab和常用的数据库

DB Toolbox连接Matlab和常用的数据库数据库工具箱(DB Toolbox)让用户使用MATLAB强大数据分析和可视化工具功能处理存储在数据库中的数据的复杂分析。
在MATLAB环境下工作,可以用结构化查询语言(SQL)命令读,写数据库的数据,进行简单和高级条件的数据查询。
并且可以连接MATLAB和数据库包括Oracle,Sybase,Microsoft SQL Server和Informix。
可以用单一MATLAB同时访问多个数据库,进行大数据量的事务处理。
不懂SQL的用户可以用Visual Query Builder处理数据。
一、重点1)鲁棒接口能力。
用ODBC/JDBC连接数据库,包括Oracle,Sybase SQL Server,Sybase SQL Anywhere,Microsoft SQL Server, MicrosoftAccess,Informix Ingres.2)SQL语法。
在MATLAB环境直接执行SQL查询3)动态导入数据。
调节SQL查询,把数据导入MATLAB。
数据库工具箱满足小的和大的查询。
4)数据类型保存。
在数据导入和导出行为MATLAB保存数据类型5)同时访问多个数据库。
从数据库导入数据,对该数据执行计算,然后导入到另一个数据库。
6)处理大数据集的能力。
7)连续状态的数据库连接:一旦和某个数据库的连接建立后,数据库一直是打开的,除非在MATLAB中执行关闭语句。
这提高了数据库的读取速度,减少了不必要的命令来调入,输出数据。
8)Visual Query Builder.该图形用户接口列数据源和所有表和字段,不懂SQL的用户可以访问和查询数据库二、函数列表2.1数据库访问函数2.1.1 close 关闭数据库连接CLOSE Close database connection.CLOSE(CONNECT) closes the database connection.CONNECT is a database connection object returned by DATABASE.2.1.2 commit 数据库改变参数COMMIT Make database changes permanent.COMMIT(C) makes all changes since the previous commit or rollback permanent and releases connection's database locks. C is the database connection.2.1.3 database 连接数据库DATABASE Connect to database.CONNECT = DATABASE(INSTANCE,USERNAME,PASSWORD,DRIVER,DATABASEURL)returns a database connection object. INSTANCE is the name of the database, USERNAME is the user name. PASSWORD is the password that permits access to the database. DRIVER is a JDBC driver name and DATABASEURL is the URL for the database. The latter arguments are optional but both must be used in conjunction with each other.Example:JDBC connection:conn=database('oracle','scott','tiger','oracle.jdbc.driver.OracleDriver','j dbc:oracle:oci7:')where:'oracle' is the database name.'scott' is the user name.'tiger' is the password.'oracle.jdbc.driver.OracleDriver' is the JDBC driver to be used to make the connection.'jdbc:oracle:oci7:' is the URL as defined by the Driver vendor to establish a connection with the database.2.1.4 exec 执行SQL语句和打开油标EXEC Execute SQL statement and open CursorCURSOR = EXEC(CONNECT,SQLQUERY,QTIMEOUT) returns a cursor object.CONNECT is a database object returned by DATABASE. sqlQuery is a valid SQL statement. Use FETCH to retrieve data associatedwith CURSOR.Example:cursor = exec(connect,'select * from emp')where:connect is a valid database object.'select * from emp' is a valid SQL statement that selects all columns from the emp table.2.1.5 get 得到数据库属性VALUE = GET(HANDLE, PROPERTY) will return the VALUE of the PROPERTYspecified for the given HANDLE to a Database object.VALUE = GET(HANDLE) returns VALUE as a structure containing all theproperty values of the Database object.2.1.6 insert 导出MATLAB单元数组数据到数据库表INSERT Export MATLAB cell array data into database table.INSERT(CONNECT,TABLENAME,FIELDNAMES,DATA).CONNECT is a database connection handle structure, FIELDNAMES is a string array of database column names, TABLENAME is the database table, DATA is a MATLAB cell array. For improved write performance and support for additional data types, use the function FASTINSERT.Example:The following INSERT command inserts the contents of the cell array in to the database table yearlySales for the columns defined in the cell array colNames.insert(conn,'yearlySales',colNames,monthlyTotals);whereThe cell array colNames contains the value:colNames = {'salesTotal'};monthlyTotals is a cell array containing the data to be inserted into the database table yearlySalesinsert(conn,'yearlySales',colNames,monthlyTotals);2.1.7 isconnection 判断数据库连接是否有效ISCONNECTION Detect if database connection is valid.X = ISCONNECTION(C) returns 1 if C is a valid database connection and 0 otherwise.2.1.8isreadonly 判断数据库连接是否只读2.1.9 ping 得到数据库连接信息PING Get status information about database connection.P = PING(CONNECT) determines the status of a database connection.CONNECT is a database connection object. If the connection is valid status information for a database connection is returned.If the connection is invalid then an error message is returned.Example:p = ping(connect)where connect is a database connection.This function returns the following information for an ODBC connection.For a Microsoft Access database:p =DatabaseProductName: ACCESSDatabaseProductVersion: 3.5 JetJDBCDriverName: JDBC-ODBC Bridge (odbcjt32.dll)JDBCDriverVersion: 1.1001 (03.50.3428.00)MaxDatabaseConnections: 64CurrentUserName: adminDatabaseURL: jdbc:odbc:ralphAutoCommitTransactions: TrueThis function returns the following information for a JDBC connection.For an ORACLE database:p =DatabaseProductName: OracleDatabaseProductVersion: Oracle7 Server Release 7.3.3.0.0 - Production Release With the distributed, replication and parallel query options PL/SQL Release 2.3.3.0.0- Production JDBCDriverName: Oracle JDBC driverJDBCDriverVersion: 7.3.3.1.3MaxDatabaseConnections: 0CurrentUserName: scottDatabaseURL: jdbc:oracle:oci7:oracleAutoCommitTransactions: TrueThe information returned details the type of database, connection type anddriver used, username etc.2.1.10 rollback 撤销数据库变化2.1.11set 设置数据库连接属性SET Set properties for database connection.SET(H, 'PROPERTY', 'VALUE') sets the VALUE of the given PROPERTY for theDatabase object, H. SET(H) returns the list of properties that can be modified.2.1.12sql2native 转换JDBC SQL 语法为系统本身的SQL语法SQL2NATIVE Convert JDBC SQL grammar into system's native SQL grammar.N = SQL2NATIVE(C,S) converts the SQL statement string, S, intothe system's native SQL grammar. The native SQL statement is returned.C is the database connection.2.1.13 update 用MATLAB单元数组数据代替数据库表的数据UPDATE Replace data in database table with data from MATLAB cell array.UPDATE(CONNECT,TABLENAME,FIELDNAMES,DATA,WHERECLAUSE).CONNECT is a database connection object, FIELDNAMES is a string array of database column names, TABLENAME is the database table, DATA is a MATLAB cell array and WHERECLAUSE is a SQL where clause used to specify the row(s) to be updated. If WHERECLAUSE is a cell array of SQL where clauses, there should be one record of data for each entry in WHERECLAUSE. Examples:The following UPDATE command updates the contents of the cell array in to the database table yearlySales for the columns defined in the cell array colNames.update(conn,'yearlySales',colNames,monthlyTotals,whereClause);where The cell array colNames contains the value:colNames = {'salesTotal'};monthlyTotals is a cell array containing the data to beused in updating the appropriate rows of the database table yearlySales.whereClause is a string that contains the where condition that must be satisfied for a row in the table to be updated.whereClause = 'where month = ''Nov'''is an example of a valid whereClause.update(conn,'yearlySales',colNames,monthlyTotals,whereClause);To specify multiple constraints, use the following syntax:update(conn,'Table1',{'FloatColumn','realfloatcolumn'},{4,7.8;5,33.5},{'where One = true';'where One = false'});The columns FloatColumn and realfloatcolumn will be updated accordinglydepending on the value of the column One in the corresponding record.2.2数据库游标访问函数2.2.1attr 获得的数据集的列属性ATTR Get attributes of columns in fetched data set.ATTRIBUTES = ATTR(CURSOR,COLUMN) returns the attributes of a single table column, defined by the input argument COLUMN, or all the table columns, if the COLUMN argument is not defined, in the data set set described by the fetch and resultSet elements of the input argument CURSOR.Example:To return the attributes for all columns/fields in the SQLselect statement the sql attr command is used as follows:columnAtts = attr(cursor)This will return a struct array with the following structure elements:fieldName - Database column/field name.typeName - String indicating the data type.typeValue - Numeric value for indicating the data type.columnWidth - Width of database column/field.precision - Precision value for float and double data types. Empty value returned for strings.scale - Precision value for real and numeric data types. Empty value returned for strings.currency - Flag to indicate whether the column/field is a currency column/field.readOnly - Flag to indicate whether column/field is read only.nullable - Flag to indicate whether column/field can contain a null.To access an element of the array and view the elements type columnAtts(1) and the following would be displayed.fieldName: 'EmployeeID'typeName: 'LONG'typeValue: 4columnWidth: 11precision: []scale: []currency: 'false'readOnly: 'true'nullable: 'false'To return the attributes for a single column/field in the SQL .select statement the ATTR command is used as follows:columnAtts = attr(cursor,1)To view the data type columnAtts and the following information would be displayed.fieldName: 'EmployeeID'typeName: 'LONG'typeValue: 4columnWidth: 11precision: []scale: []currency: 'false'readOnly: 'true'nullable: 'false'2.2.2close 关闭游标CLOSE(CURSOR) closes the database cursor.CURSOR is a cursor structure with all elements defined.2.2.3cols 获得的数据集的列数值COLS Get number of columns in fetched data set.COLUMNS = COLS(CURSOR) returns the number of columns in a database table. CURSOR is a cursor structure in which all elements have values.Example:columns = cols(cursor)Function returns the number of columns selected in the SQL query to columns.For example, issuing the SQL query, against the Microsoft Access database Northwind.'select * from employees'returns all columns from the database table employees.Invoking the sqlcols command as follows:columns = cols(cursor)returns the following value to the variable columns:columns = 17indicating there are 17 fields in cursor.2.2.4columnnames 获得的数据集的列名称2.2.5fetch 导入数据到MATLAB单元数组FETCH Import data into MATLAB using connection handle.X = FETCH(CONN,SQLSTRING,ROWINC) imports database data into MATLAB given the connection handle, CONN, the SQL string, SQLSTRING.Optionally, a row increment can be specified to retrieve the data in ROWINC records at a time.For example:x = fetch(conn,'select * from tablename')will return the requested data as a cell array, numeric matrix orstructure depending on the setting of the DataReturnFormat preference.2.2.6get 得到游标对象属性GET Get property of cursor object.VALUE = GET(HANDLE, PROPERTY) will return the VALUE of the PROPERTY specified for the given HANDLE to a Cursor object.VALUE = GET(HANDLE) returns a structure where each field name is the name of a property of HANDLE and each field contains the value of that property.2.2.7querytimeout 数据库SQL查询成功的时间QUERYTIMEOUT Get time allowed for a database SQL query to succeed.TIMEOUT = QUERYTIMEOUT(CURSOR) returns the current value of time allowed for a database query to be successful. CURSOR is a cursor object.Example:time = querytimeout(cursor)where cursor is a valid database cursor.time will contain the current value for timing out on a SQL query.2.2.8rows 获取数据集的行数ROWS Get number of rows in fetched data set.NROWS = ROWS(CURSOR) returns the number of rows retrieved by a database fetch operation. CURSOR is a cursor structure in which all elements have values.Example:nrows = rows(cursor)upon execution of the function nrows contains the the number of rows returned by the fetch. cursor=exec(conn,'select * from employees');cursor=fetch(cursor);nrows=rows(cursor)nrows = 9indicating there are 9 rows returned by FETCH.2.2.9set 设置游标获取的行限制SET Set RowLimit for cursor fetch.SET(H, 'PROPERTY', 'VALUE') sets the VALUE of the given PROPERTY for the Database Cursor object, H.S = SET(H) returns the list of valid properties.2.2.10width 获取数据集的列宽WIDTH Get field size of column in fetched data set.WTH = WIDTH(CURSOR,COLUMNNUMBER) returns the width of a specific column in database table. CURSOR is a cursor object and COLUMNNUMBER is an integer that specifies the column. Example:cursor=exec(conn,'select * from employees');cursor=fetch(cursor);colwidth=width(cursor,3)MATLAB returns:colwidth = 10indicating the width of column 3 is 12 bytes.2.3数据库元数据函数2.3.1bestrowid 得到数据库表唯一行标识BESTROWID Get database table unique row identifier.B = BESTROWID(D,C,S,T) returns the set of table columns that uniquely identifies a row. D is the database metadata object,C is the catalog, S is the schema, and T is the table.B = BESTROWID(D,C,S) returns the unique row identifier for all tables associated with the given catalog and schema.2.3.2columnprivileges 得到数据库列优先权COLUMNPRIVILEGES Get database column privileges.P = COLUMNPRIVILEGES(D,C,S,T,L) returns the privileges for the columns associatedwith the database metadata D, the catalog C, the schema S, the table T, and the column L.P = COLUMNPRIVILEGES(D,C,S,T) returns the privileges for all columns for the given catalog, schema, and table.2.3.3columns 得到数据库表列名称COLUMNS Get database table column names.P = COLUMNS(D,C,S,T) returns the columns for the given database metadata D, the catalog C, the schema S, and the table T.P = COLUMNS(D,C,S) returns the columns for all tables for the givencatalog and schema.P = COLUMNS(D,C) returns all columns for all tables of all schemas for the given catalog.2.3.4crossreference 得到主健和外健信息CROSSREFERENCE Get information about primary and foreign keys.E = CROSSREFERENCE(D,PC,PS,PT,FC,FS,FT) returns the foreign and primary key information for a given database metadata object D, primary catalog PC,primary schema PS, primary table PT, foreign catalog FC, foreign schema FS, and foreign table FT.2.3.5dmd 创建数据库元数据对象DMD Construct database metadata object.D = DMD(C) constructs a database metadata object. The metadata object is used to call methods that return the properties of the database connection's metadata. C is a database connection object.2.3.6exportedkeys 得到导出外部健信息EXPORTEDKEYS Get information about exported foreign keys.E = EXPORTEDKEYS(D,C,S,T) returns the exported key information for a given database metadata object D, catalog C, schema S, and table T.E = EXPORTEDKEYS(D,C,S) returns the exported key information for all tables associated with the database metadata object D, catalog C, and schema S.2.3.7get 得到数据库元数据属性GET Get database metadata properties.V = GET(D,'PropertyName') returns the value of the specified properties for the database meta data object, D. 'PropertyName' is a string or cell array of strings containing property names.V = GET(D) returns a structure where each field name is the nameof a property of D and each field contains the value of that property2.3.8importedkeys 得到导入外健信息IMPORTEDKEYS Get information about imported foreign keys.E = IMPORTEDKEYS(D,C,S,T) returns the imported key information for a given database metadata object D, catalog C, schema S, and table T.E = IMPORTEDKEYS(D,C,S) returns the imported key information for all tables associated with the database metadata object D, catalog C, and schema S.2.3.9indexinfo 得到数据库表的索引和统计INDEXINFO Get indices and statistics for database table or schema.N = INDEXINFO(D,C,S,T) returns the table indices and statistics for the database metadata object D, catalog C, schema S, and table T.2.3.10primarykeys 从数据库表或结构得到主健信息PRIMARYKEYS Get primary key information for database table or schema(结构).E = PRIMARYKEYS(D,C,S,T) returns the primary key information for a given database metadata object D, catalog C, schema S, and table T.E = PRIMARYKEYS(D,C,S) returns the primary key information for all tables associated with the database metadata object D, catalog C, and schema S.2.3.11procedurecolumns 得到目录存储程序参数和结果列PROCEDURECOLUMNS Get catalog's stored procedure parameters and result columns.P = PROCEDURECOLUMNS(D,C,S) returns stored procedure parameter information for the given database metadata D, catalog C, and schema S.P = PROCEDURECOLUMNS(D,C) returns stored procedure parameter information for all schemas of the given catalog.2.3.12procedures 得到目录存储程序PROCEDURES Get catalog's stored procedures.P = PROCEDURES(D,C,S) returns stored procedure information for the given database metadata D, catalog C, and schema S.P = PROCEDURES(D,C) returns stored procedure information for all schemas of the given catalog.2.3.13supports 判断是否支持数据库元数据SUPPORTS Detect if property is supported by database metadata object.V = SUPPORTS(D,'PropertyName') returns 1 if the specified properties for the database meta data object, D, are supported and0 otherwise. 'PropertyName' is a string or cell array of strings containing property names.V = SUPPORTS(D) returns a structure where each field name is the name of a property of D and each field contains a 1 or 0 for a supported or unsupported property, respectively.2.3.14tableprivileges 得到数据库表优先权TABLEPRIVILEGES Get database table privileges.P = TABLEPRIVILEGES(D,C,S,T) returns the privileges for the tables associated with the database metadata D, the catalog C, the schema S, and the table T.P = TABLEPRIVILEGES(D,C,S) returns the privileges for all tables for the given catalog and schema. P = TABLEPRIVILEGES(D,C) returns the privileges for all tables of all schemas of the given catalog.2.3.15tables 得到数据库表名称TABLES Get database table names.T = TABLES(D,C,S) returns the list of tables and table types for the database with the catalog name C and schema name S. D is the database metadata object resulting from a database connection object.T = TABLES(D,C) returns all tables and table types for all schemas of the given catalog.2.3.16versioncolumns 得到自动更新表列VERSIONCOLUMNS Get automatically updated table columns.P = VERSIONCOLUMNS(D,C,S,T) returns the table's columns that are automatically updated when any row value is updated given the database metadata object, catalog C, schema S and table T. P = VERSIONCOLUMNS(D,C,S) returns the information for all tables associated with the given catalog and schema.P = VERSIONCOLUMNS(D,C) returns the information for all tables of all schemas of the given catalog.2.4 数据库工具箱驱动器函数2.4.1driver 创建数据库驱动器对象DRIVER Construct database driver object.D = DRIVER(S) constructs a database driver object from variableS which is a database URL string of the form jdbc:odbc:<name> or <name>. The first driver which recognizes the given database URL is returned.2.4.2 get 获得数据库驱动器属性GET Get database driver properties.V = GET(D,'PropertyName') returns the value of the specified properties for the database driver object, D. 'PropertyName' isa string or cell array of strings containing property names.V = GET(D) returns a structure where each field name is the nameof a property of D and each field contains the value of that property.2.4.3 isdriver 判断驱动器是否为有效的JDBC驱动对象ISDRIVER Detect if driver is a valid JDBC driver object.X = ISDRIVER(D) returns 1 if D is a valid JDBC driver object.2.4.4 isURl 判断数据库URL是否是有效的ISURL Detect if the database URL is valid.X = ISURL(D,S) returns 1 if S is a valid database URL for the given driver, D. The given URL, of the form 'jdbc:odbc:<name>' for example, is tested against the given database driver object D.2.4.5 isJDBC 判断驱动器是否为JDBCISJDBC Detect if driver is JDBC-compliant.X = ISJDBC(D) returns 1 if D is JDBC compliant.2.4.6 register 加载数据库驱动器REGISTER Load database driver.REGISTER(D) loads the database driver D.2.5 数据库工具箱结果设置函数2.5.1 clearwarnings取消结果设置警报CLEARWARNINGS Clear the warnings for the resultset.CLEARWARNINGS(R) clears the warnings reported for the resultset R.2.5.2close 关闭结果显示对象CLOSE Close resultset object.CLOSE(R) closes the resultset object, R, and frees its associated resources.2.5.3get 获得结果设置对象的属性GET Get resultset properties.V = GET(D,'PropertyName',N) returns the value of the specified properties for the resultset object, D. 'PropertyName'is a string or cell array of strings containing property names. N is the column number or name for which the properties are returned.V = GET(D,N) returns a structure where each field name is the nameof a property of D and each field contains the value of that property for the column index or name N. All properties are returned for the given columns.V = GET(D) returns all properties for all columns.2.5.4 isnullcolumn 判断结果设置的最后记录是否为空ISNULLCOLUMN Detect if last record read in resultset was null.X = ISNULLCOLUMN(R) returns 1 if the last record of the resultset,R, read was null and 0 otherwise.2.5.5 namecolumn 获得结果设置对象列的列名NAMECOLUMN Map resultset column name to resultset column index.X = NAMECOLUMN(R,N) maps a resultset column name, N, to a resultset column index. R is the resultset. N is a cell array of strings.2.5.6 resultset 创建结果设置对象RESULTSET Construct resultset object.R = RESULTSET(C) returns a resultset object given a cursor object,C.2.6 可视化SQl查询建立函数(Visual Query Builder functions:)2.6.1 getdatasources 获得系统有效数据源GETDATASOURCES Return valid data sources on system.D = GETDATASOURCES returns the valid data sources on the system.If D is empty, the ODBC.INI file is valid but no data sources have been defined. If D equals -1, the ODBC.INI file could not be opened.D is returned as a cell array of strings containing the data source namesif any are present on the system.2.6.2 loginconnect 数据源连接LOGINCONNECT Datasource connection.LOGINCONNECT(DATASOURCE) Prompts for the datasource username and password.2.6.3querybuilder建立可视化SQl查询窗口QUERYBUILDER Start visual SQL query builder.2.6.4 showdata 在交互窗口中显示数据SHOWDATA Display data in interactive window.SHOWDATA(A,F,T) displays the given cell array of data, A, in an interactive figure window.The unique entries for each column of data are displayed.Clicking on a item in the figure displays information regarding the number of matching items found and additional correlation data. F is a cellarray of strings used as X axis labels.If F is not supplied, no X axislabels are displayed.T is the figure window title string. If T is not supplied, no title is displayed. SHOWDATA(A,F,T) displays the given cell array of data, A, in an interactive figure window. The unique entries for each column of data are displayed.Clicking on a item in the figure displays information regarding the numberof matching items found and additional correlation data.F is a cell array of strings used as X axis labels.If F is not supplied, no X axis labels are displayed.T is the figure window title string.If T is not supplied, no title is displayed.四、例子sourceName=input('Enter the source Name:','s'); %获取数据源的名称(dbtest)Timeout=logintimeout(5); %允许登录连接时间最长为5sconn=database(sourceName,'sa','123'); %获取数据库连接对象ping(conn) %测试数据库连接状态dbmeta=dmd(conn); %获取数据元对象t=tables(dbmeta,'tutorial'); %获取cata为tutorial的表名[trow,tcolumn]=size(t); %获取返回数组的大小index=1;for i=1:trow %由于表中既包含了系统表格if strcmp(t{i,2},'TABLE') %又包含了用户表格,需要在其中tablename{1,index}=t{i,1}; %找出用户表格,对t数组的每一行 index=index+1; %的第二个元素判断是table则为用end %户表。
Matlab中的数据库连接与查询技巧

Matlab中的数据库连接与查询技巧简介:Matlab是一种强大的数学计算软件,除了在数值计算和科学工程领域得到广泛应用外,它也具备与数据库连接和查询的功能。
本文将介绍在Matlab中如何实现与数据库的连接和查询,并提供一些应用技巧和最佳实践。
一、数据库连接技巧在Matlab中,可以使用不同的方法来建立与数据库的连接。
首先,需要安装Matlab的Database Toolbox以获得数据库相关的功能。
具体的安装方法可以参考Matlab官方文档。
1. 直接连接最简单的方法是使用Matlab中提供的直接连接函数。
这些函数允许用户直接指定数据库的连接参数,例如数据库类型、主机地址、端口号等。
一旦成功连接,就可以执行查询和更新操作。
2. 使用ODBC连接另一种常用的方法是使用ODBC(Open Database Connectivity)驱动来连接数据库。
ODBC提供了一个统一的接口,使得可以使用通用的SQL语句来操作不同类型的数据库。
在Matlab中,可以使用database函数来创建一个ODBC连接对象并指定相应的数据源和驱动。
3. 使用JDBC连接JDBC(Java Database Connectivity)是一种Java语言的接口标准,用于连接不同数据库并执行相关操作。
Matlab中可以通过创建java对象的方式来调用JDBC功能。
这种方法可以轻松地连接不同类型的数据库,并且还可以利用Java的强大功能来处理复杂的查询和数据处理任务。
二、数据库查询技巧一旦成功建立了与数据库的连接,接下来就可以进行查询操作了。
本节将介绍一些常用的数据库查询技巧,包括基本查询、条件查询、排序、分组和连接查询。
1. 基本查询基本查询是指从数据库中检索记录的最简单形式。
在Matlab中,可以使用SQL语句来执行基本查询操作。
例如,通过使用SELECT语句和FROM子句,可以从指定的表中检索所有记录或指定列的数据。
然后,使用WHERE子句可以添加条件来进一步筛选结果。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
DB Toolbox连接Matlab和常用的数据库数据库工具箱(DB Toolbox)让用户使用MATLAB强大数据分析和可视化工具功能处理存储在数据库中的数据的复杂分析。
在MATLAB环境下工作,可以用结构化查询语言(SQL)命令读,写数据库的数据,进行简单和高级条件的数据查询。
并且可以连接MATLAB和数据库包括Oracle,Sybase,Microsoft SQL Server和Informix。
可以用单一MATLAB同时访问多个数据库,进行大数据量的事务处理。
不懂SQL的用户可以用Visual Query Builder处理数据。
一、重点1)鲁棒接口能力。
用ODBC/JDBC连接数据库,包括Oracle,Sybase SQL Server,Sybase SQL Anywhere,Microsoft SQL Server, MicrosoftAccess,Informix Ingres.2)SQL语法。
在MATLAB环境直接执行SQL查询3)动态导入数据。
调节SQL查询,把数据导入MATLAB。
数据库工具箱满足小的和大的查询。
4)数据类型保存。
在数据导入和导出行为MATLAB保存数据类型5)同时访问多个数据库。
从数据库导入数据,对该数据执行计算,然后导入到另一个数据库。
6)处理大数据集的能力。
7)连续状态的数据库连接:一旦和某个数据库的连接建立后,数据库一直是打开的,除非在MATLAB中执行关闭语句。
这提高了数据库的读取速度,减少了不必要的命令来调入,输出数据。
8)Visual Query Builder.该图形用户接口列数据源和所有表和字段,不懂SQL的用户可以访问和查询数据库二、函数列表2.1数据库访问函数2.1.1 close 关闭数据库连接CLOSE Close database connection.CLOSE(CONNECT) closes the database connection.CONNECT is a database connection object returned by DATABASE.2.1.2 commit 数据库改变参数COMMIT Make database changes permanent.COMMIT(C) makes all changes since the previous commit or rollback permanent and releases connection's database locks. C is the database connection.2.1.3 database 连接数据库DATABASE Connect to database.CONNECT = DATABASE(INSTANCE,USERNAME,PASSWORD,DRIVER,DATABASEURL)returns a database connection object. INSTANCE is the name of the database, USERNAME is the user name. PASSWORD is the password that permits access to the database. DRIVER is a JDBC driver name and DATABASEURL is the URL for the database. The latter arguments are optional but both must be used in conjunction with each other.Example:JDBC connection:conn=database('oracle','scott','tiger','oracle.jdbc.driver.OracleDriver','j dbc:oracle:oci7:')where:'oracle' is the database name.'scott' is the user name.'tiger' is the password.'oracle.jdbc.driver.OracleDriver' is the JDBC driver to be used to make the connection.'jdbc:oracle:oci7:' is the URL as defined by the Driver vendor to establish a connection with the database.2.1.4 exec 执行SQL语句和打开油标EXEC Execute SQL statement and open CursorCURSOR = EXEC(CONNECT,SQLQUERY,QTIMEOUT) returns a cursor object.CONNECT is a database object returned by DATABASE. sqlQuery is a valid SQL statement. Use FETCH to retrieve data associatedwith CURSOR.Example:cursor = exec(connect,'select * from emp')where:connect is a valid database object.'select * from emp' is a valid SQL statement that selects all columns from the emp table.2.1.5 get 得到数据库属性VALUE = GET(HANDLE, PROPERTY) will return the VALUE of the PROPERTYspecified for the given HANDLE to a Database object.VALUE = GET(HANDLE) returns VALUE as a structure containing all theproperty values of the Database object.2.1.6 insert 导出MATLAB单元数组数据到数据库表INSERT Export MATLAB cell array data into database table.INSERT(CONNECT,TABLENAME,FIELDNAMES,DATA).CONNECT is a database connection handle structure, FIELDNAMES is a string array of database column names, TABLENAME is the database table, DATA is a MATLAB cell array. For improved write performance and support for additional data types, use the function FASTINSERT. Example:The following INSERT command inserts the contents of the cell array in to the database table yearlySales for the columns defined in the cell array colNames.insert(conn,'yearlySales',colNames,monthlyTotals);whereThe cell array colNames contains the value:colNames = {'salesTotal'};monthlyTotals is a cell array containing the data to be inserted into the database table yearlySales insert(conn,'yearlySales',colNames,monthlyTotals);2.1.7 isconnection 判断数据库连接是否有效ISCONNECTION Detect if database connection is valid.X = ISCONNECTION(C) returns 1 if C is a valid database connection and 0 otherwise.2.1.8isreadonly 判断数据库连接是否只读2.1.9 ping 得到数据库连接信息PING Get status information about database connection.P = PING(CONNECT) determines the status of a database connection.CONNECT is a database connection object. If the connection is valid status information for a database connection is returned.If the connection is invalid then an error message is returned.Example:p = ping(connect)where connect is a database connection.This function returns the following information for an ODBC connection.For a Microsoft Access database:p =DatabaseProductName: ACCESSDatabaseProductVersion: 3.5 JetJDBCDriverName: JDBC-ODBC Bridge (odbcjt32.dll)JDBCDriverVersion: 1.1001 (03.50.3428.00)MaxDatabaseConnections: 64CurrentUserName: adminDatabaseURL: jdbc:odbc:ralphAutoCommitTransactions: TrueThis function returns the following information for a JDBC connection.For an ORACLE database: p =DatabaseProductName: OracleDatabaseProductVersion: Oracle7 Server Release 7.3.3.0.0 - Production Release With the distributed, replication and parallel query options PL/SQL Release 2.3.3.0.0- Production JDBCDriverName: Oracle JDBC driverJDBCDriverVersion: 7.3.3.1.3MaxDatabaseConnections: 0CurrentUserName: scottDatabaseURL: jdbc:oracle:oci7:oracleAutoCommitTransactions: TrueThe information returned details the type of database, connection type anddriver used, username etc.2.1.10 rollback 撤销数据库变化2.1.11set 设置数据库连接属性SET Set properties for database connection.SET(H, 'PROPERTY', 'VALUE') sets the VALUE of the given PROPERTY for theDatabase object, H. SET(H) returns the list of properties that can be modified.2.1.12sql2native 转换JDBC SQL 语法为系统本身的SQL语法SQL2NATIVE Convert JDBC SQL grammar into system's native SQL grammar.N = SQL2NATIVE(C,S) converts the SQL statement string, S, intothe system's native SQL grammar. The native SQL statement is returned.C is the database connection.2.1.13 update 用MATLAB单元数组数据代替数据库表的数据UPDATE Replace data in database table with data from MATLAB cell array.UPDATE(CONNECT,TABLENAME,FIELDNAMES,DATA,WHERECLAUSE).CONNECT is a database connection object, FIELDNAMES is a string array of database column names, TABLENAME is the database table, DATA is a MATLAB cell array and WHERECLAUSE is a SQL where clause used to specify the row(s) to be updated. If WHERECLAUSE is a cell array of SQL where clauses, there should be one record of data for each entry in WHERECLAUSE. Examples:The following UPDATE command updates the contents of the cell array in to the database table yearlySales for the columns defined in the cell array colNames.update(conn,'yearlySales',colNames,monthlyTotals,whereClause);where The cell array colNames contains the value:colNames = {'salesTotal'};monthlyTotals is a cell array containing the data to beused in updating the appropriate rows of the database table yearlySales.whereClause is a string that contains the where condition that must be satisfied for a row in the table to be updated.whereClause = 'where month = ''Nov'''is an example of a valid whereClause.update(conn,'yearlySales',colNames,monthlyTotals,whereClause);To specify multiple constraints, use the following syntax:update(conn,'Table1',{'FloatColumn','realfloatcolumn'},{4,7.8;5,33.5},{'where One = true';'where One = false'});The columns FloatColumn and realfloatcolumn will be updated accordinglydepending on the value of the column One in the corresponding record.2.2数据库游标访问函数2.2.1attr 获得的数据集的列属性ATTR Get attributes of columns in fetched data set.ATTRIBUTES = ATTR(CURSOR,COLUMN) returns the attributes of a single table column, defined by the input argument COLUMN, or all the table columns, if the COLUMN argument is not defined, in the data set set described by the fetch and resultSet elements of the input argument CURSOR. Example:To return the attributes for all columns/fields in the SQLselect statement the sql attr command is used as follows:columnAtts = attr(cursor)This will return a struct array with the following structure elements:fieldName - Database column/field name.typeName - String indicating the data type.typeValue - Numeric value for indicating the data type.columnWidth - Width of database column/field.precision - Precision value for float and double data types. Empty value returned for strings.scale - Precision value for real and numeric data types. Empty value returned for strings.currency - Flag to indicate whether the column/field is a currency column/field.readOnly - Flag to indicate whether column/field is read only.nullable - Flag to indicate whether column/field can contain a null.To access an element of the array and view the elements type columnAtts(1) and the following would be displayed.fieldName: 'EmployeeID'typeName: 'LONG'typeValue: 4columnWidth: 11precision: []scale: []currency: 'false'readOnly: 'true'nullable: 'false'To return the attributes for a single column/field in the SQL .select statement the ATTR command is used as follows:columnAtts = attr(cursor,1)To view the data type columnAtts and the following information would be displayed.fieldName: 'EmployeeID'typeName: 'LONG'typeValue: 4columnWidth: 11precision: []scale: []currency: 'false'readOnly: 'true'nullable: 'false'2.2.2close 关闭游标CLOSE(CURSOR) closes the database cursor.CURSOR is a cursor structure with all elements defined.2.2.3cols 获得的数据集的列数值COLS Get number of columns in fetched data set.COLUMNS = COLS(CURSOR) returns the number of columns in a database table. CURSOR is a cursor structure in which all elements have values.Example:columns = cols(cursor)Function returns the number of columns selected in the SQL query to columns.For example, issuing the SQL query, against the Microsoft Access database Northwind.'select * from employees'returns all columns from the database table employees.Invoking the sqlcols command as follows:columns = cols(cursor)returns the following value to the variable columns:columns = 17indicating there are 17 fields in cursor.2.2.4columnnames 获得的数据集的列名称2.2.5fetch 导入数据到MATLAB单元数组FETCH Import data into MATLAB using connection handle.X = FETCH(CONN,SQLSTRING,ROWINC) imports database data into MATLAB given the connection handle, CONN, the SQL string, SQLSTRING.Optionally, a row increment can be specified to retrieve the data in ROWINC records at a time.For example:x = fetch(conn,'select * from tablename') will return the requested data as a cell array, numeric matrix orstructure depending on the setting of the DataReturnFormat preference.2.2.6get 得到游标对象属性GET Get property of cursor object.VALUE = GET(HANDLE, PROPERTY) will return the VALUE of the PROPERTY specified for the given HANDLE to a Cursor object.VALUE = GET(HANDLE) returns a structure where each field name is the name of a property of HANDLE and each field contains the value of that property.2.2.7querytimeout 数据库SQL查询成功的时间QUERYTIMEOUT Get time allowed for a database SQL query to succeed.TIMEOUT = QUERYTIMEOUT(CURSOR) returns the current value of time allowed for a database query to be successful. CURSOR is a cursor object.Example:time = querytimeout(cursor)where cursor is a valid database cursor.time will contain the current value for timing out on a SQL query.2.2.8rows 获取数据集的行数ROWS Get number of rows in fetched data set.NROWS = ROWS(CURSOR) returns the number of rows retrieved by a database fetch operation. CURSOR is a cursor structure in which all elements have values.Example:nrows = rows(cursor)upon execution of the function nrows contains the the number of rows returned by the fetch. cursor=exec(conn,'select * from employees');cursor=fetch(cursor);nrows=rows(cursor)nrows = 9indicating there are 9 rows returned by FETCH.2.2.9set 设置游标获取的行限制SET Set RowLimit for cursor fetch.SET(H, 'PROPERTY', 'VALUE') sets the VALUE of the given PROPERTY for the Database Cursor object, H.S = SET(H) returns the list of valid properties.2.2.10width 获取数据集的列宽WIDTH Get field size of column in fetched data set.WTH = WIDTH(CURSOR,COLUMNNUMBER) returns the width of a specific column in database table. CURSOR is a cursor object and COLUMNNUMBER is an integer that specifies the column. Example:cursor=exec(conn,'select * from employees');cursor=fetch(cursor);colwidth=width(cursor,3)MATLAB returns:colwidth = 10indicating the width of column 3 is 12 bytes.2.3数据库元数据函数2.3.1bestrowid 得到数据库表唯一行标识BESTROWID Get database table unique row identifier.B = BESTROWID(D,C,S,T) returns the set of table columns that uniquely identifies a row. D is the database metadata object,C is the catalog, S is the schema, and T is the table.B = BESTROWID(D,C,S) returns the unique row identifier for all tables associated with the given catalog and schema.2.3.2columnprivileges 得到数据库列优先权COLUMNPRIVILEGES Get database column privileges.P = COLUMNPRIVILEGES(D,C,S,T,L) returns the privileges for the columns associatedwith the database metadata D, the catalog C, the schema S, the table T, and the column L.P = COLUMNPRIVILEGES(D,C,S,T) returns the privileges for all columns for the given catalog, schema, and table.2.3.3columns 得到数据库表列名称COLUMNS Get database table column names.P = COLUMNS(D,C,S,T) returns the columns for the given database metadata D, the catalog C, the schema S, and the table T.P = COLUMNS(D,C,S) returns the columns for all tables for the givencatalog and schema.P = COLUMNS(D,C) returns all columns for all tables of all schemas for the given catalog.2.3.4crossreference 得到主健和外健信息CROSSREFERENCE Get information about primary and foreign keys.E = CROSSREFERENCE(D,PC,PS,PT,FC,FS,FT) returns the foreign and primary key information for a given database metadata object D, primary catalog PC,primary schema PS, primary table PT, foreign catalog FC, foreign schema FS, and foreign table FT.2.3.5dmd 创建数据库元数据对象DMD Construct database metadata object.D = DMD(C) constructs a database metadata object. The metadata object is used to call methods that return the properties of the database connection's metadata. C is a database connection object.2.3.6exportedkeys 得到导出外部健信息EXPORTEDKEYS Get information about exported foreign keys.E = EXPORTEDKEYS(D,C,S,T) returns the exported key information for a given database metadata object D, catalog C, schema S, and table T.E = EXPORTEDKEYS(D,C,S) returns the exported key information for all tables associated with the database metadata object D, catalog C, and schema S.2.3.7get 得到数据库元数据属性GET Get database metadata properties.V = GET(D,'PropertyName') returns the value of the specified properties for the database meta data object, D. 'PropertyName' is a string or cell array of strings containing property names.V = GET(D) returns a structure where each field name is the nameof a property of D and each field contains the value of that property2.3.8importedkeys 得到导入外健信息IMPORTEDKEYS Get information about imported foreign keys.E = IMPORTEDKEYS(D,C,S,T) returns the imported key information for a given database metadata object D, catalog C, schema S, and table T.E = IMPORTEDKEYS(D,C,S) returns the imported key information for all tables associated with the database metadata object D, catalog C, and schema S.2.3.9indexinfo 得到数据库表的索引和统计INDEXINFO Get indices and statistics for database table or schema.N = INDEXINFO(D,C,S,T) returns the table indices and statistics for the database metadata object D, catalog C, schema S, and table T.2.3.10primarykeys 从数据库表或结构得到主健信息PRIMARYKEYS Get primary key information for database table or schema(结构).E = PRIMARYKEYS(D,C,S,T) returns the primary key information for a given database metadata object D, catalog C, schema S, and table T.E = PRIMARYKEYS(D,C,S) returns the primary key information for all tables associated with the database metadata object D, catalog C, and schema S.2.3.11procedurecolumns 得到目录存储程序参数和结果列PROCEDURECOLUMNS Get catalog's stored procedure parameters and result columns.P = PROCEDURECOLUMNS(D,C,S) returns stored procedure parameter information for the given database metadata D, catalog C, and schema S.P = PROCEDURECOLUMNS(D,C) returns stored procedure parameter information for all schemas of the given catalog.2.3.12procedures 得到目录存储程序PROCEDURES Get catalog's stored procedures.P = PROCEDURES(D,C,S) returns stored procedure information for the given database metadata D, catalog C, and schema S.P = PROCEDURES(D,C) returns stored procedure information for all schemas of the given catalog.2.3.13supports 判断是否支持数据库元数据SUPPORTS Detect if property is supported by database metadata object.V = SUPPORTS(D,'PropertyName') returns 1 if the specified properties for the database meta data object, D, are supported and0 otherwise. 'PropertyName' is a string or cell array of strings containing property names.V = SUPPORTS(D) returns a structure where each field name is the name of a property of D and each field contains a 1 or 0 for a supported or unsupported property, respectively.2.3.14tableprivileges 得到数据库表优先权TABLEPRIVILEGES Get database table privileges.P = TABLEPRIVILEGES(D,C,S,T) returns the privileges for the tables associated with the database metadata D, the catalog C, the schema S, and the table T.P = TABLEPRIVILEGES(D,C,S) returns the privileges for all tables for the given catalog and schema. P = TABLEPRIVILEGES(D,C) returns the privileges for all tables of all schemas of the given catalog.2.3.15tables 得到数据库表名称TABLES Get database table names.T = TABLES(D,C,S) returns the list of tables and table types for the database with the catalog name C and schema name S. D is the database metadata object resulting from a database connection object.T = TABLES(D,C) returns all tables and table types for all schemas of the given catalog.2.3.16versioncolumns 得到自动更新表列VERSIONCOLUMNS Get automatically updated table columns.P = VERSIONCOLUMNS(D,C,S,T) returns the table's columns that are automatically updated when any row value is updated given the database metadata object, catalog C, schema S and table T.P = VERSIONCOLUMNS(D,C,S) returns the information for all tables associated with the given catalog and schema.P = VERSIONCOLUMNS(D,C) returns the information for all tables of all schemas of the given catalog.2.4 数据库工具箱驱动器函数2.4.1driver 创建数据库驱动器对象DRIVER Construct database driver object.D = DRIVER(S) constructs a database driver object from variableS which is a database URL string of the form jdbc:odbc:<name> or <name>. The first driver which recognizes the given database URL is returned.2.4.2 get 获得数据库驱动器属性GET Get database driver properties.V = GET(D,'PropertyName') returns the value of the specified properties for the database driver object, D. 'PropertyName' isa string or cell array of strings containing property names.V = GET(D) returns a structure where each field name is the nameof a property of D and each field contains the value of that property.2.4.3 isdriver 判断驱动器是否为有效的JDBC驱动对象ISDRIVER Detect if driver is a valid JDBC driver object.X = ISDRIVER(D) returns 1 if D is a valid JDBC driver object.2.4.4 isURl 判断数据库URL是否是有效的ISURL Detect if the database URL is valid.X = ISURL(D,S) returns 1 if S is a valid database URL for the given driver, D. The given URL, of the form 'jdbc:odbc:<name>' for example, is tested against the given database driver object D.2.4.5 isJDBC 判断驱动器是否为JDBCISJDBC Detect if driver is JDBC-compliant.X = ISJDBC(D) returns 1 if D is JDBC compliant.2.4.6 register 加载数据库驱动器REGISTER Load database driver.REGISTER(D) loads the database driver D.2.5 数据库工具箱结果设置函数2.5.1 clearwarnings取消结果设置警报CLEARWARNINGS Clear the warnings for the resultset.CLEARWARNINGS(R) clears the warnings reported for the resultset R.2.5.2close 关闭结果显示对象CLOSE Close resultset object.CLOSE(R) closes the resultset object, R, and frees its associated resources.2.5.3get 获得结果设置对象的属性GET Get resultset properties.V = GET(D,'PropertyName',N) returns the value of the specified properties for the resultset object, D. 'PropertyName'is a string or cell array of strings containing property names. N is the column number or name for which the properties are returned.V = GET(D,N) returns a structure where each field name is the nameof a property of D and each field contains the value of that property for the column index or name N. All properties are returned for the given columns.V = GET(D) returns all properties for all columns.2.5.4 isnullcolumn 判断结果设置的最后记录是否为空ISNULLCOLUMN Detect if last record read in resultset was null.X = ISNULLCOLUMN(R) returns 1 if the last record of the resultset,R, read was null and 0 otherwise.2.5.5 namecolumn 获得结果设置对象列的列名NAMECOLUMN Map resultset column name to resultset column index.X = NAMECOLUMN(R,N) maps a resultset column name, N, to a resultset column index. R is the resultset. N is a cell array of strings.2.5.6 resultset 创建结果设置对象RESULTSET Construct resultset object.R = RESULTSET(C) returns a resultset object given a cursor object,C.2.6 可视化SQl查询建立函数(Visual Query Builder functions:)2.6.1 getdatasources 获得系统有效数据源GETDATASOURCES Return valid data sources on system.D = GETDATASOURCES returns the valid data sources on the system.If D is empty, the ODBC.INI file is valid but no data sources have been defined. If D equals -1, the ODBC.INI file could not be opened.D is returned as a cell array of strings containing the data source namesif any are present on the system.2.6.2 loginconnect 数据源连接LOGINCONNECT Datasource connection.LOGINCONNECT(DATASOURCE) Prompts for the datasource username and password.2.6.3querybuilder建立可视化SQl查询窗口QUERYBUILDER Start visual SQL query builder.2.6.4 showdata 在交互窗口中显示数据SHOWDATA Display data in interactive window.SHOWDATA(A,F,T) displays the given cell array of data, A, in an interactive figure window.The unique entries for each column of data are displayed.Clicking on a item in the figure displays information regarding the number of matching items found and additional correlation data. F is a cellarray of strings used as X axis labels.If F is not supplied, no X axislabels are displayed.T is the figure window title string. If T is not supplied, no title is displayed. SHOWDATA(A,F,T) displays the given cell array of data, A, in an interactive figure window. The unique entries for each column of data are displayed.Clicking on a item in the figure displays information regarding the numberof matching items found and additional correlation data.F is a cell array of strings used as X axis labels.If F is not supplied, no X axis labels are displayed.T is the figure window title string.If T is not supplied, no title is displayed.四、例子sourceName=input('Enter the source Name:','s'); %获取数据源的名称(dbtest)Timeout=logintimeout(5); %允许登录连接时间最长为5sconn=database(sourceName,'sa','123'); %获取数据库连接对象ping(conn) %测试数据库连接状态dbmeta=dmd(conn); %获取数据元对象t=tables(dbmeta,'tutorial'); %获取cata为tutorial的表名[trow,tcolumn]=size(t); %获取返回数组的大小index=1;for i=1:trow %由于表中既包含了系统表格if strcmp(t{i,2},'TABLE') %又包含了用户表格,需要在其中tablename{1,index}=t{i,1}; %找出用户表格,对t数组的每一行 index=index+1; %的第二个元素判断是table则为用end %户表。