mysql - java load data infile query discarding wrong lines -
java application insert data mysql using load data infile query. in csv file, wrong formatted values lacking rows, improper fields (string value integer value). if there non-correct record(line) on file, java application throws exception , not add any records correct lines. if execute same query same file using heidi sql program (sql client program), add records, non-correct lines (put null value lacking fields etc). want java application behave sql client, put lines @ least insert correctly well-formed lines.
thanks.
sql
load data infile '/a.txt' table test_data fields terminated ','
code snippet
public void query(string query, connection conn) throws sqlexception { preparedstatement ps = null; try { ps = conn.preparestatement(query); ps.executeupdate(); } catch (mysqltransactionrollbackexception e) { logger.error("", e); throw new mysqltransactionrollbackexception(); } catch (sqlexception e) { logger.error("", e); throw new sqlexception(e); } { if (ps != null) { try { ps.close(); } catch (exception e) { logger.error("", e); } } try { conn.close(); } catch (sqlexception e) { logger.error("", e); } } }
it cannot discard wrong lines might causing parsing failure of entire file.with algorithms can done, dont think there 100% accuracy.
Comments
Post a Comment