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

2 visualizzazioni (ultimi 30 giorni)
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 Commenti
Geoff Hayes
Geoff Hayes il 27 Mag 2016
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 il 27 Mag 2016
Modificato: Alvindra Pratama il 27 Mag 2016
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

Accedi per commentare.

Risposta accettata

Geoff Hayes
Geoff Hayes il 29 Mag 2016
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 Commenti
Geoff Hayes
Geoff Hayes il 29 Mag 2016
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});

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by