0

I'm trying to upload the contents of a text file using this:

  myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/sys", "root", "*****8");

        Statement myStmt = myConn.createStatement();

        String sql="LOAD DATA INFILE"+ "'C:\\Users\\willf\\Documents\\comps sci\\NEA\\V1.4\\map files\\map.txt'"+"INTO TABLE sys.mazes";


        myStmt.executeUpdate(sql);

"java.sql.SQLException: File 'C:\ProgramData\MySQL\MySQL Server 8.0\Data\UserswillfDocumentscomps sciNEAV1.4map filesmap.txt' not found (OS errno 2 - No such file or directory)"

As you can see the filepath is completely different to what i'm giving it.

1
  • 1
    Remove the two quotes '. Use "C:\\Users\\willf\\Documents\\comps sci\\NEA\\V1.4\\map files\\map.txt" Commented Oct 29, 2019 at 15:12

1 Answer 1

1

MySQL is looking for a relative path using forward slashes. Try this instead: "'/C:/Users/willf/Documents/comps sci/NEA/V1.4/map files/map.txt'"

Sign up to request clarification or add additional context in comments.

5 Comments

thanks ,file path seems to be right now ,but says can't find file with error "OS errno 13 - Permission denied"
@Fred As far as I know, LOAD DATE INFILE is executed by the MySQL server process, which is run by a user that doesn't have access to your user folder.
@MarkRotteveel I tried using LOCAL aswell but its not supported in my sql version apparently.
whats the recommened way of uploading the contents of a txt file ?
@Fred Depends on the type of file. If it's a SQL file, the recommended way is just to read it in via the command line. For a CSV, there are multiple approaches, none bad. Best way would probably be to just write a Java program that parses it and updates the table row by row.

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.