-2
JAVA를 사용하여 CSV 파일을 Oracle 테이블로 가져 오는 방법이 있습니까?ssql없이 파일 csv에서 오라클로 데이터 가져 오기
JAVA를 사용하여 CSV 파일을 Oracle 테이블로 가져 오는 방법이 있습니까?ssql없이 파일 csv에서 오라클로 데이터 가져 오기
샘플 코드 : 당신은 다운로드하여 클래스 경로에 opencsv를 추가해야합니다
import java.io.*;
import com.opencsv.*;
import java.util.*;
import java.sql.*;
public class loadcsvinoracle {
public static void main(String[] args) throws Exception{
/* Create Connection objects */
Class.forName ("oracle.jdbc.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/db12c", "hr", "hr");
PreparedStatement sql_statement = null;
String jdbc_insert_sql = "INSERT INTO CSVFILE"
+ "(COL1, COL2, COL3) VALUES"
+ "(?,?,?)";
sql_statement = conn.prepareStatement(jdbc_insert_sql);
/* Read CSV file in OpenCSV */
String inputCSVFile = "csvfile.csv";
CSVReader reader = new CSVReader(new FileReader(inputCSVFile));
String [] nextLine;
int lnNum = 0;
//loop file , add records to batch
while ((nextLine = reader.readNext()) != null) {
lnNum++;
/* Bind CSV file input to table columns */
sql_statement.setString(1, nextLine[0]);
sql_statement.setString(2, nextLine[1]);
sql_statement.setString(3, nextLine[2]);
// Add the record to batch
sql_statement.addBatch();
System.out.println ("New line " + nextLine[0] + nextLine[1] + nextLine[2]);
}
//We are now ready to perform a bulk batch insert
int[] totalRecords = new int[7];
try {
totalRecords = sql_statement.executeBatch();
} catch(BatchUpdateException e) {
//you should handle exception for failed records here
totalRecords = e.getUpdateCounts();
}
System.out.println ("Total records inserted in bulk from CSV file " + totalRecords.length);
/* Close prepared statement */
sql_statement.close();
/* COMMIT transaction */
conn.commit();
/* Close connection */
conn.close();
}
}
.
[this] (https://www.mkyong.com/java/how-to-read-and-parse-csv-file-in-java/) – user75ponic
SQL \ * 로더 또는 외부 사용 테이블. 왜 오라클이 당신을 위해 그들을 제공 할 때 자신의 수입 루틴을 작성합니까? – APC
sql * 로더 설치 후 컨트롤러 파일 코드로 java를 사용하여 CSV를 가져올 수 있습니까? –