Importing CSV into MySQL through JAVA -
so i'm trying import csv file mysql database through java program. program imports that's in file, it's suppose to, first row, send end of table, , program see it's there, if search nr, says doesn't exists. , if go directly database table , edit nr(if nr 137, , edit , write 137 again) program recognize nr, , if search it, find, , database table organizes , sends entry suppose be. don't see logic in this. me out, i'd appreciated.
load data infile 'c:\\users\\carla.desktop-9364k9k\\desktop\\alunos_1.csv' table utentes character set utf8 fields terminated ',' (nrprocesso, nome, @nome_resumido, ano, turma, @subsidio, @nome_ee, @nif, @email, @obs) set subsidio = if(@subsidio='','nenhum',@subsidio), nome_resumido = if(@nome_resumido='',null,@nome_resumido), nome_ee = if(@nome_ee='',null,@nome_ee), nif = if(@nif = '', null,@nif), email = if(@email='',null,@email), obs = if(@obs='',null,@obs);
thanks in advance.
you have do check cell/column value , form sql inject in mysql.
public list<object> getrecordingslistfromcsv(string csvfilelocation, string mp3filelocation, string mp3filelocation2, string savefilelocation, channelsftp sftp) { map<string, file> recordingsfilesmap = null; bufferedreader br = null; list<string> errorfileslist = new arraylist<>(); list<object> templist = new linkedlist<>(); try { csvrows = 0; recordingsfilesmap = new linkedhashmap<>(); br = new bufferedreader(new filereader(csvfilelocation)); string line = br.readline(); scriptlog.info("\n" + csvfilelocation + " loaded. parsing file..."); while ((line = br.readline()) != null) { string[] csvarray = parsecsvlinetoarray(line); // system.out.println(arrays.aslist(csvarray) + "\n\n"); if (csvarray[0].trim().isempty()) { continue; } /* stuff here */ csvrows++; } } catch (filenotfoundexception e) { scriptlog.error("\n---error---\n file not found: " + csvfilelocation); string errorstr = "type=" + e.tostring(); errorstr += "stacktrace=" + arrays.tostring(e.getstacktrace()); scriptlog.error(errorstr); } catch (ioexception e) { string errorstr = "type=" + e.tostring(); errorstr += "stacktrace=" + arrays.tostring(e.getstacktrace()); scriptlog.error(errorstr); } { if (br != null) { try { br.close(); } catch (ioexception e) { system.out.println(e.tostring()); } } }
hope @ extent!!
Comments
Post a Comment