gistfile1.txt package com.yang.base;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.sql.Connection;import java.sql.DriverManager;public class ka
package com.yang.base; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.sql.Connection; import java.sql.DriverManager; public class ka { private static int failed = 0; private static int success = 0; private static final String MYSQLDRIVER = "com.mysql.jdbc.Driver"; private static final String MYSQLURL = "jdbc:mysql://localhost:3306/db?user=root&password=&useUnicode=true&characterEncoding=utf8&autoReconnect=true"; //使用时修改下数据库连接信息 /** * 数据库更新 * * @param sql */ public static void executeSQL(StringBuilder sql) { try { Class.forName(MYSQLDRIVER); Connection conns = DriverManager.getConnection(MYSQLURL); conns.prepareStatement(sql.toString()).execute(); //执行sql 语句 } catch (Exception e) { e.printStackTrace(); } } /** * 把SQL批量插入数据库 */ public static void getSql(){ try { File file=new File("d:/csdn/"); String test[]; test=file.list(); //D盘下所有的文档(sql语句) for(int i=0;i批量导入文件夹“手机号码归属地”下的所有文本文件到数据库 import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class ReadConfigureFile3 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/test"; String username = "root"; String password = "1234"; Connection conn = null; Statement stmt = null; try { conn = DriverManager.getConnection(url, username, password); stmt = conn.createStatement(); } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //得到所选择文件夹 File file = new File("D:\\share\\手机号码归属地"); //得到选择文件夹的全路径 String path = file.getAbsolutePath(); //取得文件夹下的所有文件 String[] files = file.list(); try { //设置数据手动提交,自己管理事务 conn.setAutoCommit(false); } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }// //遍历文件夹下所有文件 for(int i=0; i