import csv to mysql with java -


so have csv file, , want import mysql, far in phpmyadmin can import following line:

load data infile 'c:\\users\\angel silva\\documents\\test.csv' table registros fields enclosed '"' terminated ',' escaped '"' lines terminated '\n'  

my java program is:

public class recover { public static void main(string[] args){     try {         string filename ="c:\\users\\angel silva\\documents\\test.csv";         string query=null;         class.forname("com.mysql.jdbc.driver").newinstance();         connection conn = drivermanager.getconnection("jdbc:mysql://localhost:3306/gg", "root", "");         statement stmt = conn.createstatement();         query = "load data infile 'c:\\users\\angel silva\\documents\\test.csv' table registros fields enclosed '\"' terminated ',' escaped '\"' lines terminated '\\n'";         stmt.executequery(query);         resultset rs = stmt.executequery(query);        } catch (classnotfoundexception ex) {         logger.getlogger(recover.class.getname()).log(level.severe, null, ex);     } catch (instantiationexception ex) {         logger.getlogger(recover.class.getname()).log(level.severe, null, ex);     } catch (illegalaccessexception ex) {         logger.getlogger(recover.class.getname()).log(level.severe, null, ex);     } catch (sqlexception ex) {         logger.getlogger(recover.class.getname()).log(level.severe, null, ex);     } } 

}

i following errors:

ene 24, 2016 1:28:33 pm recover main severe: null java.sql.sqlexception: row 1 truncated; contained more data tha there input columns @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:946) @ com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:2985) @ com.mysql.jdbc.mysqlio.sendcommand(mysqlio.java:1631) @ com.mysql.jdbc.mysqlio.sqlquerydirect(mysqlio.java:1723) @ com.mysql.jdbc.connection.execsql(connection.java:3277) @ com.mysql.jdbc.connection.execsql(connection.java:3206) @ com.mysql.jdbc.statement.executequery(statement.java:1232) @ recover.main(recover.java:29) 

as have said if input sentence query directly phpymyadmin can recover table in java doesnt work

any idea im doing wrong?

lines terminated '\\r\\n' 

(as it's windows)


Comments