Retrieving BINARY or OTHER Sun Java SQL Data Types

This example retrieves images from the SampleDB data source using a sample file that parses image data, matlabroot/toolbox/database/vqb/parsebinary.m.

  1. Connect to the SampleDB data source.

    conn = database('SampleDB', '', '');
    
  2. Specify cellarray as the data return format preference.

    setdbprefs('DataReturnFormat','cellarray');
    
  3. Import the EmployeeID and Photo columns of data from the Employees table.

    curs = exec(conn, 'select EmployeeID,Photo from Employees')
    curs = fetch(curs);
    
  4. View the data you imported.

    curs.Data
    ans = 
    
        [1]    [21626x1 int8]
        [2]    [21626x1 int8]
        [3]    [21722x1 int8]
        [4]    [21626x1 int8]
        [5]    [21626x1 int8]
        [6]    [21626x1 int8]
        [7]    [21626x1 int8]
        [8]    [21626x1 int8]
        [9]    [21626x1 int8]

  5. Assign the image element you want to the variable photo.

    photo = curs.Data{1,2};
    
  6. Run parsebinary. This program writes the retrieved data to a file, strips ODBC header information from it, and displays photo as a bitmap image in a figure window. Ensure that your current directory is writable so that the output of parsebinary can be written to it.

    cd 'I:\MATLABFiles\myfiles
    parsebinary(photo, 'BMP');
    

    For more information on parsebinary, enter help parsebinary or view the M-file in the MATLAB Editor/Debugger by entering open parsebinary.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS