简体   繁体   English

如何使用Java从客户端和服务器位于不同物理系统上的csv文件上载数据到oracle中

[英]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. 我想将客户端上的csv文件中的数据上传到服务器上的oracle数据库,该服务器实际上是使用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 具有oracle的服务器
  • A server with java 使用Java的服务器
  • A file csv on the server with java 使用Java的服务器上的文件csv

And you need to save the data from csv to oracle. 并且您需要将数据从csv保存到oracle。 Correct? 正确? If so this is a standard java application with I/O to read the file and JDBC access to a remote database. 如果是这样,这是一个具有I / O的标准Java应用程序,用于读取文件和对远程数据库的JDBC访问。

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. 要访问远程数据库,只需将URL连接中的127.0.0.1(或localhost)替换为远程数据库的ip。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何处理从Java客户端上传服务器端HTTP文件 - How to handle Server side HTTP file upload from Java client Java客户端如何将文件上传到远程HDFS服务器或从远程HDFS服务器下载文件? - How a Java client upload/download a file to/from remote HDFS server? 如何使用OFBIZ将文件从客户端上传到服务器? - How to Upload a file from client to server using OFBIZ? 如何使用jersey-client V2.13(从客户端到服务器)在JAVA中上传750MB的文件? - How to upload a file of 750MB in JAVA, using jersey-client V2.13 (from a client to a server)? 使用java和hibernate在oracle服务器目录上上传文件 - to upload file on oracle server directory using java and hibernate 使用Dojo文件上传客户端将其他数据发送到Java服务器端 - Send additional data to Java server-side using Dojo file upload client-side 如何使用Java将数据从Cassandra导出到CSV文件 - How to export data from Cassandra to CSV file using Java 如何使用java将数据从csv文件插入elasticsearch - How to insert data into elasticsearch from csv file using java 来自不同PC的不同客户端使用Java中的ip与服务器通信 - different client from different pc communicate with server using ip in java 如何使用Java Spring将带有上传文件的多部分/表单数据表单重新发送到其他服务器 - How to resend post multipart/form-data form with upload file to different server with Java Spring
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM