0

Fix the error and i need to import(store) csv files to mysql database table

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'");

Returned errors :

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)
2
  • ... and what exactly is the problem? Some error message? Data not correctly imported? Commented Aug 8, 2013 at 10:12
  • 2
    Since you are in Java, I think you should be doing terminated by '\\r\\n' and maybe also 'E:\\\\Book.csv'. That's because the literal you write will be escaped by Java, which will pass it to the SQL server, which will escape it again. If you write \\B, the server is receiving \B. Commented Aug 8, 2013 at 11:25

1 Answer 1

1

Try this, you forgot to escape ":

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'");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.