view m-toolbox/classes/+utils/@jmysql/query.m @ 18:947e2ff4b1b9
database-connection-manager
Update plist.FROM_REPOSITORY_PLIST and plist.TO_REPOSITORY_PLIST
author
Daniele Nicolodi <nicolodi@science.unitn.it>
date
Mon, 05 Dec 2011 16:20:06 +0100 (2011-12-05)
parents
91f21a0aab35
children
line source
+ − function varargout = query(conn, query, varargin)
+ − % QUERY Query an LTPDA repository.
+ − %
+ − % DEPRECATED! Use utils.mysql.execute instead!
+ − %
+ − % CALL: [results] = query(conn, q, varargin)
+ − % [results, cnames] = query(conn, q, varargin)
+ − %
+ − % INPUTS:
+ − %
+ − % conn - database connection object implementing java.sql.Connection
+ − % query - a valid SQL query
+ − % varargin - optional query parameters
+ − %
+ − % OUTPUTS:
+ − %
+ − % results - a cell-array of the results
+ − % cnames - a cell-array of the column names in the query
+ − %
+ − % VERSION: $Id: query.m,v 1.1 2009/07/27 19:46:21 hewitson Exp $
+ − %
+ −
+ − warning('!!! deprecated. use utils.mysql.execute instead');
+ −
+ − if ~isa(conn, 'java.sql.Connection')
+ − error('### first argument should be a java.sql.Connection object');
+ − end
+ −
+ − stmt = conn.prepareStatement(query);
+ − for kk = 1:numel(varargin)
+ − stmt.setObject(kk, varargin{kk});
+ − end
+ −
+ − % execute query
+ − resultSet = stmt.executeQuery();
+ −
+ − % set outputs
+ − if nargout > 0
+ − varargout{1} = resultSet;
+ − if nargout == 2
+ − % get column names from the meta data
+ − rsm = resultSet.getMetaData;
+ − Nc = rsm.getColumnCount;
+ − colnames = cell(1,Nc);
+ − for kk=1:Nc
+ − colnames{kk} = char(rsm.getColumnName(kk));
+ − end
+ − varargout{2} = colnames;
+ − end
+ − end
+ −
+ − end
+ −