package test.ip;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
public class TestIP {
// DROP TABLE IF EXISTS `ip`;
// CREATE TABLE `ip` (
// `id` int(11) NOT NULL AUTO_INCREMENT,
// `startIP` varchar(50) DEFAULT NULL,
// `endIP` varchar(50) DEFAULT NULL,
// `country` varchar(100) DEFAULT NULL,
// `local` varchar(100) DEFAULT NULL,
// PRIMARY KEY (`id`)
// ) ENGINE=MyISAM DEFAULT CHARSET=gbk;
public static void main(String[] args) throws Exception{
try{
//从配置文件中得到SqlMapClient对象
Reader reader2 = Resources.getResourceAsReader("sqlMapConf.xml");
SqlMapClient sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader2);
reader2.close();
//IPData1.txt 需要是utf8转存一下,另外将文件里面的tab键转成空格
BufferedReader reader = new BufferedReader(new FileReader("F:/IPData1.txt"));
boolean flag = true;
List res = new ArrayList();
while(flag){
String lineStr = reader.readLine();
if(lineStr!= null &&!lineStr.isEmpty()){
String str[] = lineStr.split(" ");
Map lineRes = new HashMap();
if(str.length > 0){
lineRes.put("startIP", str[0]);
}
if(str.length > 1){
lineRes.put("endIP", str[1]);
}
if(str.length > 2){
lineRes.put("country", str[2]);
}
if(str.length > 3){
lineRes.put("local", str[3]);
}
ip users = (ip) sqlMapper.insert("ipSql.add", lineRes);
}else{
flag = false;
System.out.println("停止了");
}
}
}catch (Exception e) {
System.out.println(e);
}
}
}