フィルターのクリア

Why the result is Ljava.lang.string after i select multiple images & store the to MySql?

1 回表示 (過去 30 日間)
I have chosen several images from a one folder, after i select 3 images & displayed them into edit text.
Edit text displayed like this :
D:/1.jpg
D:/2.jpg
D:/3.jpg
But at the table in gui which displayed that data after i save them to MySql, the data become Ljava.lang.string, not like edit text displayed above. How can i displayed the data like edit text above again?
  2 件のコメント
Geoff Hayes
Geoff Hayes 2016 年 5 月 27 日
Alvindra - please show the code that you are using to extract the text from your control and the SQL statement that you have written to save the data to your database. Also, please confirm that the correct filenames (those from above) are being written to the database. If they are, then perhaps it is your SQL statement to get the data from your database that has been incorrectly formed. In either case, you need to show some of the code that you have written.
Alvindra Pratama
Alvindra Pratama 2016 年 5 月 27 日
編集済み: Alvindra Pratama 2016 年 5 月 27 日
For additional information, Ljava.lang.string only happens if I choose more than one image.
Here the picture before i insert all data to the database :
And here the picture after i insert all data to the database & display data from the database to a table in the GUI and then show them back to Their edit text using CellSelectionCallback at that table :
For the code, here the code i used to select multiple images :
%if true
[filename,pathname,filterindex]=uigetfile({'*.jpg';'*.bmp';'*.png';'*.tif'}, 'MultiSelect', 'on', 'Buka Gambar', 'H:\SKRIPSI\Citra Latih\');
if ~isequal(filename,0)
switch(class(filename))
case 'double'
disp('Selection aborted')
case 'char'
%disp('Only one image has been selected')
h = msgbox('Citra Yang Terpilih Hanya Satu');
ChosenImages = strcat(pathname,filename)
set(handles.txtketfoto,'String',ChosenImages);
case 'cell'
numberOfFiles = length(filename);
q = msgbox([num2str(numberOfFiles) ' Citra Telah Terpilih']);
selectedFiles = cell(1,numberOfFiles);
for i = 1:numberOfFiles
selectedFiles{1,i} = fullfile(pathname, filename{1,i});
disp(selectedFiles{1,i})
set(handles.txtketfoto,'String', fullfile(pathname, filename), 'Max', 2)
end
otherwise
disp('Unexpected output')
end
else
return
%end
Here is the code to save all data to the database :
%if true
conn=database('pca','root','','com.mysql.jdbc.Driver','jdbc:mysql://localhost:3306/');
id = get(handles.txtid, 'String');
nama = get(handles.txtnama, 'String');
alamat = get(handles.txtalamat, 'String');
foto = get(handles.txtketfoto, 'String');
datainsert(conn,'tbl_pca',{'id','nama','alamat','foto'},{id,nama,alamat,foto});
close(conn);
%end

サインインしてコメントする。

採用された回答

Geoff Hayes
Geoff Hayes 2016 年 5 月 29 日
Alvindra - unfortunately, I can't run your code (I observe errors as soon as I run launch the GUI). I think the problem is that when you try to save the files to the database, you extract the filenames as
foto = get(handles.txtketfoto, 'String');
foto is most likely a cell array of strings and so you will have to treat it differently. How should this be written to your database? If you have n files, should you insert n records in to the database, one for each file? Or should you convert this cell array of strings to a single string where each filename is separated by a (for example) semi-colon?
  5 件のコメント
Geoff Hayes
Geoff Hayes 2016 年 5 月 29 日
Do this after you have gotten the list of photos:
foto = get(handles.txtketfoto, 'String');
if strcmpi(class(foto),'cell')
myFilesAsString = '';
% etc.
else
myFilesAsString = foto;
end
datainsert(conn,'tbl_pca',{'id','nama','alamat','foto'},{id,nama,alamat,myFilesAsString});
Alvindra Pratama
Alvindra Pratama 2016 年 5 月 30 日
Thank you very very much for helping me sir

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeString についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by