<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 431,  comments - 344,  trackbacks - 0
    一年前一個(gè)項(xiàng)目里面使用了CSVJDBC,當(dāng)時(shí)覺得這個(gè)工具特別好,今天又遇到客戶給我一個(gè)CSV文件,里面有20萬的數(shù)據(jù),需要導(dǎo)入到數(shù)據(jù)庫(kù)中進(jìn)行分析處理。所以首選當(dāng)然是CSVJDBC了。具體代碼實(shí)現(xiàn)如下:

    package com.founder.demo;

    import Java.sql.Connection;
    import Java.sql.DriverManager;
    import Java.sql.PreparedStatement;
    import Java.sql.ResultSet;
    import Java.sql.Statement;

    public class ImportCSV {

     public static void main(String[] args) {
      try {
       // load the driver into memory
       Class.forName("org.relique.jdbc.csv.CsvDriver");

       // create a connection. The first command line parameter is assumed to
       //  be the directory in which the .csv files are held
       Connection conn = DriverManager
         .getConnection("jdbc:relique:csv:H:\\PythonWorkSpace");

       // create a Statement object to execute the query with
       Statement stmt = conn.createStatement();

       // Select the columns from csv file
       ResultSet results = stmt
         .executeQuery("SELECT ORDER_NO,ARTICLE_NO,CATALOG_NO,DESCRIPTION,QUANTITY,ISO_UNIT,UNIT,MDL_NO,CAS, "
           + " MOLECULA,FORMULA,DENSITY,PRICE_EUR,UN_NO,DANGER_GR,DANGER_CLASS,ZUSATZGEFAHR1,ZUSATZGEFAHR2,R_PHRASES, "
           + " S_PHRASES,DANGER_SYMBOL,STORAGE_TEMPERATURE FROM ABCR");
       
       //MySQL
       Class.forName("com.mysql.jdbc.Driver").newInstance();
       Connection con = Java.sql.DriverManager
         .getConnection(
           "jdbc:mysql://localhost/chemicaldb?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull",
           "root", "root");

       String sql = "INSERT INTO meryer_abcr (ORDER_NO,ARTICLE_NO,CATALOG_NO,DESCRIPTION,QUANTITY,ISO_UNIT,UNIT,MDL_NO,CAS, "
         + " MOLECULA_FORMULA,MOLECULAR_WEIGHT,DENSITY,PRICE_EUR,UN_NO,DANGER_GROUP,DANGER_CLASS,ZUSATZGEFAHR1,ZUSATZGEFAHR2,R_PHRASES, "
         + " S_PHRASES,DANGER_SYMBOL,STORAGE_TEMPERATURE) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

       PreparedStatement mstmt = con.prepareStatement(sql);

       // dump out the results and set params
       while (results.next()) {
        mstmt.setString(1, results.getString("ORDER_NO"));
        mstmt.setString(2, results.getString("ARTICLE_NO"));
        mstmt.setString(3, results.getString("CATALOG_NO"));
        mstmt.setString(4, results.getString("DESCRIPTION"));
        mstmt.setString(5, results.getString("QUANTITY"));
        mstmt.setString(6, results.getString("ISO_UNIT"));
        mstmt.setString(7, results.getString("UNIT"));
        mstmt.setString(8, results.getString("MDL_NO"));
        mstmt.setString(9, results.getString("CAS"));
        mstmt.setString(10, results.getString("MOLECULA_FORMULA"));
        mstmt.setString(11, results.getString("MOLECULAR_WEIGHT"));
        mstmt.setString(12, results.getString("DENSITY"));
        mstmt.setString(13, results.getString("PRICE_EUR"));
        mstmt.setString(14, results.getString("UN_NO"));
        mstmt.setString(15, results.getString("DANGER_GROUP"));
        mstmt.setString(16, results.getString("DANGER_CLASS"));
        mstmt.setString(17, results.getString("ZUSATZGEFAHR1"));
        mstmt.setString(18, results.getString("ZUSATZGEFAHR2"));
        mstmt.setString(19, results.getString("R_PHRASES"));
        mstmt.setString(20, results.getString("S_PHRASES"));
        mstmt.setString(21, results.getString("DANGER_SYMBOL"));
        mstmt.setString(22, results.getString("STORAGE_TEMPERATURE"));
        mstmt.execute();
        
        System.out.println(results.getString("ORDER_NO"));
       }
       
       // clean up
       mstmt.close();
       con.close();
       results.close();
       stmt.close();
       conn.close();
      } catch (Exception e) {
       System.out.println("Oops-> " + e);
      }

     }

    }

    其實(shí)很簡(jiǎn)單,和操作數(shù)據(jù)庫(kù)一樣,提供了類似數(shù)據(jù)中的SQL語(yǔ)句來操作CSV文件中的數(shù)據(jù)。

    posted on 2009-08-04 11:27 周銳 閱讀(1934) 評(píng)論(0)  編輯  收藏 所屬分類: Java 、MySQL
    主站蜘蛛池模板: 免费大片黄手机在线观看| 特级aaaaaaaaa毛片免费视频| 久久亚洲精品中文字幕三区| 亚洲一区二区三区乱码A| 亚洲女人被黑人巨大进入| 亚洲av成人一区二区三区在线观看 | 久久精品国产免费观看三人同眠| 免费不卡在线观看AV| 久久免费的精品国产V∧| 亚洲精品国产免费| 国产a视频精品免费观看| 无限动漫网在线观看免费| 好吊妞998视频免费观看在线| 在线免费观看污网站| 国产成人综合久久精品免费| 夜色阁亚洲一区二区三区| 亚洲欧洲日产国码一级毛片| 亚洲综合国产一区二区三区| 亚洲国产精品一区二区第一页| 亚洲成av人在线视| 亚洲白色白色在线播放| 亚洲卡一卡二卡乱码新区| 亚洲av无码片vr一区二区三区| 国产亚洲视频在线观看网址| 国产高潮流白浆喷水免费A片 | 中文字幕看片在线a免费| 9277手机在线视频观看免费| 免费大片黄在线观看yw| 国产成人免费a在线资源| 老司机亚洲精品影视www| 久久精品国产96精品亚洲| 亚洲成人一级电影| 亚洲精品国产摄像头| 无码的免费不卡毛片视频| 97无码人妻福利免费公开在线视频 | 久久精品国产亚洲精品2020| 亚洲人成www在线播放| 免费一级特黄特色大片| 久久久99精品免费观看| 毛片A级毛片免费播放| 亚洲麻豆精品国偷自产在线91|