简体   繁体   中英

how to upload data into oracle from csv file where client and server are on different physical systems using java

I want to upload data from csv file on client to oracle database on server which is physically on different machine using java. I searched online for solutions but all solutions are working only for the case where both client and server are on same machine.

Please help

   String temp = ((System.getenv("USERPROFILE"))+("\\Documents\\"));
        String path = "";

        path = temp.replace("\\", "\\\\");
        path = path + "upload.csv";
        //System.out.println(path);
        Connection connection = MyConnection.getConnection();

            String loadQuery = "LOAD DATA LOCAL INFILE '" + path + "' INTO TABLE documents FIELDS TERMINATED BY ','" + " LINES TERMINATED BY '\n' ( Customer, address1 )";
            //System.out.println(loadQuery);
            Statement stmt = connection.createStatement();
            stmt.execute(loadQuery);

This path works if the server and client are on same machine, how to modify this when server and client are on different machine ?

If I understand well you have

  • A server with oracle
  • A server with java
  • A file csv on the server with java

And you need to save the data from csv to oracle. Correct? If so this is a standard java application with I/O to read the file and JDBC access to a remote database.

Basically here are the steps:

1) Open the csv
2) Open a database connection
3) Read a row from csv and convert it to an object (if using JPA) 
4) Save the object
5) Go to the next row until finish
6) Commit and close all resources

To access a remote database simply substitute 127.0.0.1 (or localhost) from the url connection with the ip of the remote database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM