如何将CSV文件读入本地Oracle数据库表?

时间:2015-10-02 20:14:02

标签: java oracle csv

我的目标是从CSV文件中读取,将其加载到我拥有的示例数据库表(Oracle)中。 到目前为止,我有以下Java代码:

    public class ParsingCSV {

      public static void main(String[] args) {

        ParsingCSV obj = new ParsingCSV();
        obj.run();

      }

        @SuppressWarnings("oracle.jdeveloper.java.nested-assignment")
        public void run() {

        String csvFile = "C:\\Users\\IBM_ADMIN\\Desktop\\Work\\ConnectOne_Bancorp\\Database_Work\\Book1.csv";
        BufferedReader br = null;
        String line = "";
        String cvsSplitBy = ",";

        try {

            br = new BufferedReader(new FileReader(csvFile));
            while ((line = br.readLine()) != null) {

                    // use comma as separator
                String[] country = line.split(cvsSplitBy);

                System.out.println("Country [code= " + country[4] 
                                     + " , name=" + country[5] + "]");

            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
/* boilerplate */

任何提示/指示赞赏,谢谢!

1 个答案:

答案 0 :(得分:1)

提示可能是:

  1. 下载Oracle数据库驱动程序Oracle driver

  2. 将.jar设置为您的类路径。 [java设置类路径]

  3. 注册驱动程序并连接到数据库[java connect to oracle]

  4. 执行sql“CREATE TABLE ....”[sql create table example]

  5. 对于您阅读的每一行,请执行sql =“INSERT INTO ...”[sql insert into example]

  6. 对于每一步,如果您需要更多示例和建议,我建议谷歌使用[]标签进行搜索