我正在尝试将数据插入到postgresql中的表中。
这是我的方法:
[FileName,PathName] = uigetfile('*.wav', 'Select track')
s = strcat(PathName, FileName);
%info = id3parse(path); %s was in bracket
info = audioinfo(s); % info.SampleRate; gives sample rate etc
Track_Info = cell(1,8); %create a cell array
try
id = '1';
Track_Info(1,1) = cellstr(id); %convert to cell array of strings
catch
end
try
title = info.Title;
Track_Info(1,2) = cellstr(title);
catch
end
try
artist = info.Artist;
Track_Info(1,3) = cellstr(artist);
catch
end
try
album = 'Default';
Track_Info(1,4) = cellstr(album);
catch
end
try
genre = 'Default';
Track_Info(1,5) = cellstr(genre);
catch
end
try
bpm = '100';
Track_Info(1,6) = cellstr(bpm);
catch
end
try
duration = '1:00';
Track_Info(1,7) = cellstr(duration);
catch
end
try
musickey = 'Am';
Track_Info(1,8) = cellstr(musickey);
catch
end
celldisp(Track_Info); %check contents of Track_Info
Track_Info_Test = {'"1"','"Title"','"Joe"','"Album"','"House"','"120"', '"4.00"', '"Am"'};
conn = database('harmonicmixing','postgres','jurgen','org.postgresql.Driver','jdbc:postgresql://localhost/harmonicmixing');
if(isempty(conn.message))
disp('database connected')
else
disp('cannot connect')
disp(conn.message);
return
end
colnames = { '"id"','"title"','"artist"', '"album"', '"genre"', '"bpm"', '"duration"', '"musickey"' };
fastinsert(conn, '"musiccollection"', colnames, Track_Info_Test);
commit(conn);
close(conn);
Track_Info是实际的单元格数组,它将包含有关特定轨道的信息。
然而,在上面的代码中,我正在使用另一个单元格数组Track_info_test,其中的值是硬编码的,因为现在我无法获取信息。我想要做的只是设法将数据插入表中。我已经尝试了很多东西,如上所示的代码就像它现在看起来一样。
这是我得到的错误
Error using database/fastinsert (line 285)
Java exception occurred:
java.sql.BatchUpdateException: Batch entry 0 INSERT INTO "musiccollection"
("id","title","artist","album","genre","bpm","duration","musickey") VALUES (
'"1"','"Title"','"Joe"','"Album"','"House"','"120"','"4.00"','"Am"') was aborted. Call
getNextException to see the cause.
at
org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(Abstrac tJdbc2Statement.java:2762)
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1999)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:421)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2929)
Error in add_file_to_DB (line 73)
fastinsert(conn, '"musiccollection"', colnames, Track_Info_Test);
有什么想法吗?我究竟做错了什么?备择方案?我错过了什么?新到matlab所以对我来说显而易见并不明显!
提前致谢