Import CSV file to Oracle

Is there a simple Java library or an approach that will execute an SQL query and load data into a CSV file into an Oracle database. Pls Help

+3
source share
6 answers

For such tasks, I usually use Groovy scripts , since it is very easy and quick to write and run on the JVM course.

... example:

import groovy.sql.Sql

def file1 = new File(/C:\Documents and Settings\USER\Desktop\Book1.csv/)
def reader = new FileReader(file1)

def sql = Sql.newInstance("jdbc:oracle:thin:@XXXXXX:XXXX:XXX", "SCHEMA",
      "USER", "oracle.jdbc.driver.OracleDriver")

reader.each { line ->
   fields =  line.split(';')
   sql.executeInsert("insert into YOUR_TABLE values(${fields[0]},${fields[1]},${fields[2]})")
}

This is a basic example: if you have double quotes and half-columns in your csv, you probably want to use something like OpenCSV to handle this.

+3
source

Java , . Oracle SQL * Loader, .

+5

CSV , , Oracle ( JDBC).

0

CSV ? Oracle, DIRECTORY , , , SQL . Oracle .

0

If you're open to Python, you can bulk load using SQL * Loader

loadConf=('sqlldr userid=%s DATA=%s control=%s LOG=%s.log BAD=%s.bad DISCARD=%s.dsc' % (userid,datafile, ctlfile,fn,fn,fn)).split(' ')

p = Popen(loadConf, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=False, env=os.environ)

output, err = p.communicate()

This will be much faster than inserting a row.

I downloaded the basic working example here .

0
source

Source: https://habr.com/ru/post/1772808/


All Articles