matlab-游标及查询
生活随笔
收集整理的這篇文章主要介紹了
matlab-游标及查询
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
exec創(chuàng)建游標(biāo)>> close(myconn)
>> myconn=database('cdcol','mytest','deepfuture','com.mysql.jdbc.Driver','jdbc:mysql://localhost:3306/cdcol')myconn =Instance: 'cdcol'UserName: 'mytest'Driver: 'com.mysql.jdbc.Driver'URL: 'jdbc:mysql://localhost:3306/cdcol'Constructor: [1x1 com.mathworks.toolbox.database.databaseConnect]Message: []Handle: [1x1 com.mysql.jdbc.JDBC4Connection]TimeOut: 0AutoCommit: 'on'Type: 'Database Object'>> mycurs=exec(myconn,'select * from cds')mycurs =Attributes: []Data: 0DatabaseObject: [1x1 database]RowLimit: 0SQLQuery: 'select * from cds'Message: []Type: 'Database Cursor Object'ResultSet: [1x1 com.mysql.jdbc.JDBC4ResultSet]Cursor: [1x1 com.mathworks.toolbox.database.sqlExec]Statement: [1x1 com.mysql.jdbc.StatementImpl]Fetch: 0>>help exec--- help for database/exec ---exec Execute SQL statement and open CursorCURSOR = exec(CONNECT,SQLQUERY,QTIMEOUT) returns a cursor objectCONNECT is a database object returned by DATABASE. sqlQueryis 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 allcolumns from the emp table.See also fetch.查詢結(jié)果fetch(mycurs)ans =Attributes: []Data: {3x4 cell}DatabaseObject: [1x1 database]RowLimit: 0SQLQuery: 'select * from cds'Message: []Type: 'Database Cursor Object'ResultSet: [1x1 com.mysql.jdbc.JDBC4ResultSet]Cursor: [1x1 com.mathworks.toolbox.database.sqlExec]Statement: [1x1 com.mysql.jdbc.StatementImpl]Fetch: [1x1 com.mathworks.toolbox.database.fetchTheData]>> a=ans>> a.Dataans ='Beauty' 'Ryuichi Sakamoto' [1990] [1][1x33 char] 'Groove Armada' [2001] [4]'Glee' 'Bran Van 3000' [1997] [5]>> mydata=a.Datamydata ='Beauty' 'Ryuichi Sakamoto' [1990] [1][1x33 char] 'Groove Armada' [2001] [4]'Glee' 'Bran Van 3000' [1997] [5]>> mydata{1,2}ans =Ryuichi Sakamoto>> mydata{1,1}ans =Beauty>> mydata{1,3}ans =1990 查詢參數(shù)>> cs='Beauty'cs =Beauty>> mycurs=exec(myconn,['select * from cds where titel =''',cs,''''])mycurs =Attributes: []Data: 0DatabaseObject: [1x1 database]RowLimit: 0SQLQuery: 'select * from cds where titel ='Beauty''Message: []Type: 'Database Cursor Object'ResultSet: [1x1 com.mysql.jdbc.JDBC4ResultSet]Cursor: [1x1 com.mathworks.toolbox.database.sqlExec]Statement: [1x1 com.mysql.jdbc.StatementImpl]Fetch: 0>> myres=fetch(mycurs)myres =Attributes: []Data: {'Beauty' 'Ryuichi Sakamoto' [1990] [1]}DatabaseObject: [1x1 database]RowLimit: 0SQLQuery: 'select * from cds where titel ='Beauty''Message: []Type: 'Database Cursor Object'ResultSet: [1x1 com.mysql.jdbc.JDBC4ResultSet]Cursor: [1x1 com.mathworks.toolbox.database.sqlExec]Statement: [1x1 com.mysql.jdbc.StatementImpl]Fetch: [1x1 com.mathworks.toolbox.database.fetchTheData]>>格式的配置>> setdbprefsDataReturnFormat: 'cellarray'ErrorHandling: 'store'NullNumberRead: 'NaN'NullNumberWrite: 'NaN'NullStringRead: 'null'NullStringWrite: 'null'JDBCDataSourceFile: ''UseRegistryForSources: 'yes'TempDirForRegistryOutput: 'C:\Users\DEEPFU~1\AppData\Local\Temp'DefaultRowPreFetch: '10000'>>>> help setdbprefsSETDBPREFS Set preferences for database actions for handling null values.SETDBPREFS(P,V) sets the preferences for database actions. P is thelist of properties to be set and V is the corresponding value list.SETDBPREFS(P) returns the property with its current setting.SETDBPREFS returns the property list with all current values.The valid properties are NullNumberRead, NullNumberWrite, NullStringRead,NullStringWrite, DataReturnFormat, ErrorHandling and JDBCDataSourceFile.The value for each property is entered as a string.For example, the commandsetdbprefs('NullStringRead','null')translates all NULL strings read from the database into the string'null'.The commandsetdbprefs({'NullStringRead';'NullStringWrite';'NullNumberRead';'NullNumberWrite'},...{'null';'null';'NaN';'NaN'})translates NULL strings read into the string 'null', NULL values to NaN. A NaN in thedata written to the database is translated to a NULL and a 'null' string is translated toNULL.The command setdbprefs('DataReturnFormat','cellarray') returns the datain the cursor Data field as a cell array which is the default behavior. Other values for DataReturnFormat are 'numeric' which returns the dataas a matrix of doubles and 'structure' which returns the data as a structurewith the fieldnames corresponding to the fetched fields.The command setdbprefs('ErrorHandling','store') returns any error messagesto the object Message field and will cause the next function that uses theobject to return an error. This is the default behavior. Other valuesfor ErrorHandling are 'report' which causes any function encountering an errorto report the error and stop processing and 'empty' which causes the fetchcommand to return the cursor Data field as [] when given a bad cursor objectresulting from exec.The command setdbprefs('JDBCDataSourceFile','d:\work\datasource.mat')sets the location of the JDBC data source information to the filed:\work\datasource.mat. This enables the Visual Query Builder to useboth ODBC and JDBC data sources. The command setdbprefs('JDBCDataSourceFile','')specifies that no JDBC data sources are being used by the Visual Query Builder.A single input can be used if it is a structure with fields corresponding to the validpreference names. Each field should contain a valid preferenc setting. For example,p.DataReturnFormat = 'cellarray';setdbprefs(p)帶限制輸入行數(shù)的fetch>> mycurs=exec(myconn,'select * from cds')mycurs =Attributes: []Data: 0DatabaseObject: [1x1 database]RowLimit: 0SQLQuery: 'select * from cds'Message: []Type: 'Database Cursor Object'ResultSet: [1x1 com.mysql.jdbc.JDBC4ResultSet]Cursor: [1x1 com.mathworks.toolbox.database.sqlExec]Statement: [1x1 com.mysql.jdbc.StatementImpl]Fetch: 0>> myres=fetch(mycurs,1)myres =Attributes: []Data: {'Beauty' 'Ryuichi Sakamoto' [1990] [1]}DatabaseObject: [1x1 database]RowLimit: 0SQLQuery: 'select * from cds'Message: []Type: 'Database Cursor Object'ResultSet: [1x1 com.mysql.jdbc.JDBC4ResultSet]Cursor: [1x1 com.mathworks.toolbox.database.sqlExec]Statement: [1x1 com.mysql.jdbc.StatementImpl]Fetch: [1x1 com.mathworks.toolbox.database.fetchTheData]字段相關(guān)屬性>> mycurs=exec(myconn,'select * from cds')mycurs =Attributes: []Data: 0DatabaseObject: [1x1 database]RowLimit: 0SQLQuery: 'select * from cds'Message: []Type: 'Database Cursor Object'ResultSet: [1x1 com.mysql.jdbc.JDBC4ResultSet]Cursor: [1x1 com.mathworks.toolbox.database.sqlExec]Statement: [1x1 com.mysql.jdbc.StatementImpl]Fetch: 0>> myres=fetch(mycurs)myres =Attributes: []Data: {3x4 cell}DatabaseObject: [1x1 database]RowLimit: 0SQLQuery: 'select * from cds'Message: []Type: 'Database Cursor Object'ResultSet: [1x1 com.mysql.jdbc.JDBC4ResultSet]Cursor: [1x1 com.mathworks.toolbox.database.sqlExec]Statement: [1x1 com.mysql.jdbc.StatementImpl]Fetch: [1x1 com.mathworks.toolbox.database.fetchTheData]行數(shù)>> rows(myres)ans =3列數(shù)>> cols(myres)ans =4字段名>> columnnames(myres)ans ='titel','interpret','jahr','id'>>列寬1-3列的寬度>> width(myres,1)ans =200>> width(myres,2)ans =200>> width(myres,3)ans =11>>指定列的屬性下面是第2列屬性>> attr(myres,2)ans =fieldName: 'interpret'typeName: 'VARCHAR'typeValue: 12columnWidth: 200precision: []scale: []currency: 'false'readOnly: 'false'nullable: 'true'Message: []>>或者>> myattrs=attr(myres)myattrs =1x4 struct array with fields:fieldNametypeNametypeValuecolumnWidthprecisionscalecurrencyreadOnlynullableMessage>> myattrs(1)ans =fieldName: 'titel'typeName: 'VARCHAR'typeValue: 12columnWidth: 200precision: []scale: []currency: 'false'readOnly: 'false'nullable: 'true'Message: []>>
總結(jié)
以上是生活随笔為你收集整理的matlab-游标及查询的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: matlab-JDBC操作MYSQL数据
- 下一篇: matlab数学实验结课作业答案,mat