2013-08-08 5 views
0

오류를 수정하고 내가 MySQL 데이터베이스 테이블에 CSV 파일을 (저장)를 가져CSV 파일

Class.forName("com.mysql.jdbc.Driver"); 
    java.sql.Connection c = null; 
    c = DriverManager.getConnection("jdbc:mysql://localhost:3306/Sample", "root", "root"); 
    Statement s = null; 
    s = (Statement) c.createStatement(); 
    int i = s.executeUpdate("load data local infile 'E:\\Book1.csv' into table sample.copy_table fields terminated by ',' optionally enclosed by '"' lines terminated by '\r\n'"); 

반환 오류가 필요 :이 시도

Error:Invalid character constant in this line ("load data local infile'E:\\Book1.csv'.......) 
java.sql.SQLException: Unable to open file 'E:Book1.csv'for 'LOAD DATA LOCAL INFILE' command.Due to underlying IOException: 

** BEGIN NESTED EXCEPTION ** 

java.io.FileNotFoundException 
MESSAGE: E:Book1.csv (The system cannot find the file specified) 
+0

... 정확히 무엇이 문제입니까? 일부 오류 메시지가 표시됩니까? 데이터를 올바르게 가져 오지 못 했습니까? –

+2

자바를 사용하기 때문에 '\\ r \\ n''과'E : \\\\ Book.csv'로 끝내야한다고 생각합니다. 그것은 당신이 작성한 문자가 Java에 의해 이스케이프 (escape) 될 것이기 때문입니다. 자바가 SQL 서버에 전달하면 다시 이스케이프됩니다. '\\ B'라고 쓰면 서버는'\ B'를 받는다. –

답변

1

을, 당신은 잊었 도망 치 " :

int i = s.executeUpdate("load data local infile 'E:\\Book1.csv' into table sample.copy_table fields terminated by ',' optionally enclosed by '\"' lines terminated by '\r\n'");