Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to Save JPEG images in mySQL as binary BLOB data from matlab

17 views
Skip to first unread message

Shujaat Farooqui

unread,
Mar 24, 2013, 11:48:08 AM3/24/13
to
my problem is that i need to store 19 images from a folder to a MySQL database connected through ODBC connection.

this is my code:

%browse to select folder
pathfolder=uigetdir('C:\Users\Shujaat\Pictures','Select Folder Containing Images');
%calling function by sending pathfolder parameter and get
%return in fileList
fileList = getAllFiles(pathfolder);
%count number of files
numberOfJpegs=numel(fileList);
imagePath = cell(numberOfJpegs,1);
inData = cell(numberOfJpegs,1);
Im = cell(numberOfJpegs,1);
bData = cell(numberOfJpegs,1);
for i=1:numberOfJpegs,
imagePath{i} = fileList{i};
disp(imagePath{i});
inData{i}=imread(imagePath{i});
Im{i}=rgb2gray(inData{i});
bData{i}=reshape(Im{i},[],1);
end
%get max id from database
MaxID = getMaxID('Obj_ID','Objects_Registered');
%Create a cell array containing the values to insert in table.
exdata = {MaxID+1, get(handles.edit5,'String'),get(handles.edit6,'String'),bData{1},bData{2},bData{3},bData{4},bData{5},bData{6},bData{7},bData{8},bData{9},bData{10},bData{11},bData{12},bData{13},bData{14},bData{15},bData{16},bData{17},bData{18},bData{19}};
%Create a cell array containing the column names in weights" table.
colnames = {'Obj_ID','Obj_Name','Obj_Detail','Obj_Img0','Obj_Img10','Obj_Img20','Obj_Img30','Obj_Img40','Obj_Img50','Obj_Img60','Obj_Img70','Obj_Img80','Obj_Img90','Obj_Img100','Obj_Img110','Obj_Img120','Obj_Img130','Obj_Img140','Obj_Img150','Obj_Img160','Obj_Img170','Obj_Img180'};
%Insert the data into the database.
conn = database('Object_Database','','');
fastinsert(conn, nameTable, colnames, exdata)

i am getting this error:
Error using database/fastinsert (line 259)
Java exception occurred:
sun.jdbc.odbc.JdbcOdbcBatchUpdateException: [MySQL][ODBC 5.2(a) Driver][mysqld-5.6.10]Row
size too large (> 8126). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC
or ROW_FORMAT=COMPRESSED may help. In current row format, BLOB prefix of 768 bytes is
stored inline.

at sun.jdbc.odbc.JdbcOdbcPreparedStatement.emulateExecuteBatch(Unknown Source)

at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeBatchUpdate(Unknown Source)

at sun.jdbc.odbc.JdbcOdbcStatement.executeBatch(Unknown Source)


i don't know what to do...plz help me out through this error...any help will be appreciated

Ed Yu

unread,
Dec 8, 2013, 3:49:09 PM12/8/13
to
Looks like your 19 binary columns exceeded the database page size... you need to put 19 rows instead of 19 columns for the images into the database. Also consider using Blob data type.

"Shujaat Farooqui" <shu...@hotmail.com> wrote in message <kin77o$313$1...@newscl01ah.mathworks.com>...
0 new messages