内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

java怎么實(shí)現(xiàn)批量導(dǎo)入csv文件到mysql數(shù)據(jù)庫-創(chuàng)新互聯(lián)

本篇內(nèi)容介紹了“java怎么實(shí)現(xiàn)批量導(dǎo)入csv文件到mysql數(shù)據(jù)庫”的有關(guān)知識,在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

創(chuàng)新互聯(lián)公司主要從事網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)桂林,十多年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18980820575
package com.cqu.price_prediction.farm; import java.io.File;import java.io.FileNotFoundException;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.SQLException;import java.util.Scanner; public class Read{ private static Connection con;  public static void main(String[] args) throws FileNotFoundException, SQLException {  long startTime = System.currentTimeMillis(); File file = new File("H:/AgriculturalProduct/data/farming.csv");  Scanner in = new Scanner(file);  getConnect(); System.out.println("數(shù)據(jù)庫連接成功"); insert_data(in);  long EndTime = System.currentTimeMillis(); long time = (EndTime - startTime) / 1000;  System.out.println("導(dǎo)入數(shù)據(jù)共用時(shí):" + time); }  private static void insert_data(Scanner in) throws SQLException { int count = 0; String sql = "insert into farming (province,market,type,name,standard,area,color,unit,minprice,avgprice,maxprice,entertime,time)"  + "values(?,?,?,?,?,?,?,?,?,?,?,?,?)";  con.setAutoCommit(false); PreparedStatement pstmt = con.prepareStatement(sql); in.next(); while (in.hasNext()) {  String temp1 = in.nextLine();  String[] temp = temp1.split(",");   if (temp.length < 13)  continue;   if (temp.length == 13)  {  pstmt.setString(1, temp[0]);  pstmt.setString(2, temp[1]);  pstmt.setString(3, temp[2]);  pstmt.setString(4, temp[3]);  pstmt.setString(5, temp[4]);  pstmt.setString(6, temp[5]);  pstmt.setString(7, temp[6]);  pstmt.setString(8, temp[7]);  pstmt.setString(9, temp[8]);  pstmt.setString(10, temp[9]);  pstmt.setString(11, temp[10]);  pstmt.setString(12, temp[11]);  pstmt.setString(13, temp[12]);  }   pstmt.addBatch();   count++;   if (count == 20000)  {  count = execute(pstmt, count);  } } pstmt.executeBatch(); con.commit();  }  public static int execute(PreparedStatement pstmt, int count) throws SQLException {  pstmt.executeBatch(); con.commit(); return 0;  }  private static void getConnect() { try {  Class.forName("com.mysql.jdbc.Driver");  con = DriverManager.getConnection(   "jdbc:mysql://localhost:3306/agricultural_price_prediction?useUnicode=true&characterEncoding=utf8&useServerPrepStmts=false&rewriteBatchedStatements=true",   "root", "123456"); } catch (ClassNotFoundException | SQLException e) {  // TODO Auto-generated catch block  e.printStackTrace(); } } }

“java怎么實(shí)現(xiàn)批量導(dǎo)入csv文件到mysql數(shù)據(jù)庫”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

新聞名稱:java怎么實(shí)現(xiàn)批量導(dǎo)入csv文件到mysql數(shù)據(jù)庫-創(chuàng)新互聯(lián)
本文網(wǎng)址:http://www.rwnh.cn/article16/pcodg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器做網(wǎng)站、自適應(yīng)網(wǎng)站網(wǎng)站營銷、軟件開發(fā)、商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計(jì)
高安市| 留坝县| 台东市| 屏边| 卓尼县| 凭祥市| 当雄县| 武清区| 榆树市| 北海市| 城市| 房山区| 金堂县| 黔南| 南安市| 望江县| 介休市| 建平县| 罗平县| 满城县| 阿拉善左旗| 洛隆县| 邯郸县| 西丰县| 紫金县| 岚皋县| 古浪县| 乐业县| 临江市| 微博| 工布江达县| 全州县| 青浦区| 武宁县| 彰化市| 来安县| 十堰市| 清苑县| 广西| 东明县| 山阴县|