作者:じ☆ve宝贝
发布时间:2016-02-19T16:19:38
打开软件后选择解压
我这里用一种土方法,在文本编辑器的“查找”栏中输入“ ”(9个空格,因为最大的间隔就是9个空格),“替换”栏输入分隔符“&”,然后全部替换。完成后把“查找”改成8个空格,“替换”不改,再全部替换。然后再7个、6个空格,直到全部空格都变成分隔符。 正数据:
0.0.0.0&0.255.255.255||IANA&保留地址
1.0.0.0&1.0.0.255&澳大利亚&亚太互联网络信息中心
1.0.1.0&1.0.3.255&福建省&电信
JDBCManager
package cn.studyjava;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class JDBCManager {
private String driver = "com.mysql.jdbc.Driver";
private String url = "jdbc:mysql://127.0.0.1:3306/bbs?useUnicode=true&characterEncoding=UTF-8";
private String user = "root";
private String password = "root";
/**
* 加载驱动
*
* @return
*/
public Connection getConnection() {
Connection con = null;
try {
Class.forName(driver);
con = DriverManager.getConnection(url, user, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
public void closeConnection(Connection con, PreparedStatement ps, ResultSet rs) {
if (null != con) {
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (null != ps) {
try {
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (null != rs) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
处理类:
package cn.studyjava;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
public class ReadFile {
public static void main(String[] args) throws SQLException, IOException {
FileInputStream fis=new FileInputStream("D:\\test.txt");
InputStreamReader isr=new InputStreamReader(fis, "UTF-8");
BufferedReader br = new BufferedReader(isr);
String line="";
String[] arrs=null;
long currentTimeMillis = System.currentTimeMillis();
JDBCManager jm = new JDBCManager();
Connection connection = jm.getConnection();
connection.setAutoCommit(false);
Statement stmt = connection.createStatement();
int i = 0;
int j = 0;
while ((line=br.readLine())!=null) {
try {
if(i%1000==0&& i!=0){
stmt.executeBatch(); //执行批处理
connection.commit();
System.out.println("第"+(++j)+"次");
}
arrs=line.split("&");
String operator = (arrs[3] == "CZ88.NET" ? "局域网":arrs[3]);
operator = operator.replaceAll("'", "\"");
String sql = "insert into bbs_ip (ip_start,ip_end,addr,operator) values('"+arrs[0]+"','"+arrs[1]+"','"+arrs[2]+"','"+operator+"');";
stmt.addBatch(sql);
i++;
}catch(ArrayIndexOutOfBoundsException c){
String sql = "insert into bbs_ip (ip_start,ip_end,addr,operator) values('"+arrs[0]+"','"+arrs[1]+"','"+arrs[2]+"','');";
stmt.addBatch(sql);
} catch (Exception e) {
System.err.println(line);
e.printStackTrace();
}
}
stmt.executeBatch(); //执行批处理
connection.commit();
jm.closeConnection(connection, stmt, null);
br.close();
isr.close();
fis.close();
System.err.println("用时:"+(System.currentTimeMillis()-currentTimeMillis));
}
}
SELECT * FROM bbs_ip WHERE INET_ATON('125.34.19.135') BETWEEN INET_ATON(ip_start) AND INET_ATON(ip_end);
当前很多应用都适用字符串char(15)来存储IP地址(占用16个字节),利用inet_aton()和inet_ntoa()函数,来存储IP地址效率很高,适用unsigned int 就可以满足需求,不需要使用bigint,只需要4个字节,节省存储空间,同时效率也高很多。
链接:http://pan.baidu.com/s/1o7k19GY 密码:3pvb 解压密码www.52pojie.cn/
https://studyjava.lanzous.com/icnkf7c