Useful Links
Summary
The Database Connector is a JDBC based connector for working with databases in MATLAB. The Database Connector is both an object-oriented MATLAB layer to JDBC drivers and a smart mechanism to transport data from the Java to the MATLAB side in a performing and controlled manner.
Code examples
First, a plain SQL based quick-start example is provided. Second, a slightly more advanced example is given in which the information from the database is being used to create the MATLAB Callable Statement object.
Note: Only in the first example the code for the database connector object creation and cleanup is shown.
The remainder of the examples assume the database object is present and will be cleaned up by the user when done.
Example 1: Getting started
% Install the mysql driver specifics once monkeyproof.database.install('mysql.xml'); % Create a mysql database connector object % First argument defines the database configuration to use % Next arguments are self explaining name-value pairs aa = monkeyproof.database.jdbc('mysql.xml', ... 'address', 'myserver.mydomain', ... 'databaseName', 'mydatabase'); % Just query away % The connector will ask for your credentials q = aa.query('SELECT * FROM mytable'); % Log off aa.exit % Cleanup aa.delete
Example 2: Working with callable statements
% Create statement based on procName, procSchema, procCatalog myCallStmt = aa.createCallStmt('createNewUser', 'dbo', aa.databaseName) % Note: A unique identifier 'mydatabase.dbo.createNewUser' has been % generated from the location of the procedure in the database % Show how to use the statement by generating template code myCallStmt.getCode() % The code below is based on the template code above) myNewUser = struct( ... 'firstname', 'John', ... 'lastname', 'Doe', ... 'e_mail', 'john.doe@example.com', ... 'username', 'john.doe', ... 'status', 'Active'); % Do the actual call result = aa.updateCallStmt('mydatabase.dbo.createNewUser', myNewUser)