package air3;
import tool.*;
import java.util.HashMap;
public class pro {
int creditnumber;
String[] creditp=new String[50];
String[] style=new String[50];
int[] strlong=new int[50];
String[][] datax=new String[500000][10];
HashMap<String,Integer> map = new HashMap<String,Integer>();
int s,datanumber;
String[] [[data]]=new String[5000];
String yy,mm;
String[] v=new String[5000];
String[] route=new String[5000];
String[] year=new String[5000];
String[] month=new String[5000];
int[] code=new int[5000];
int h,fastline;
int dicnumber;
String[] dic=new String[5000];
public static void main(String[] args) {
pro te=new pro();
}
pro(){
creditnumber=4;
creditp[1]="year";
creditp[2]="month";
creditp[3]="route";
creditp[4]="value";
style[1]="INTEGER";
style[2]="INTEGER";
style[3]="VARCHAR";
style[4]="VARCHAR";
strlong[3]=20;
strlong[4]=20;
String db,tab;
db="air";
tab="air6";
table sub7=new table();
sub7.credit=creditp;
sub7.creditnumber=creditnumber;
sub7.style=style;
sub7.strlong=strlong;
sub7.makedata(db,tab);
int tr;
dicnumber=0;
[[for]](tr=0;tr<98;tr++){
readfile sub77=new readfile();
sub77.makedata("air/"+tr+".txt","UTF-8");
data=sub77.data;
datanumber=sub77.datanumber;
for(s=1;s<datanumber+1;s++){
catchword sub=new catchword();
year[s]=sub.makedata(data[s],"year");
month[s]=sub.makedata(data[s],"month");
route[s]=sub.makedata(data[s],"code_route");
v[s]=sub.makedata(data[s],"value");
}
for(s=1;s<datanumber+1;s++){
route[s]=route[s].replace(" ","");
route[s]=route[s].replace(" ","");
route[s]=route[s].replace(" ","");
}
for(s=1;s<datanumber+1;s++){
h=0;
if(map.containsKey(route[s]))h=100;
if(h<50)dicnumber=dicnumber+1;
if(h<50)dic[dicnumber]=route[s];
if(h<50)map.put(route[s],dicnumber);
}
int sx;
for(s=1;s<datanumber+1;s++){
code[s]=map.get(route[s]);
}
for(s=1;s<datanumber+1;s++){
datax[s][1]=year[s];
datax[s][3]="r"+code[s];
datax[s][2]=month[s];
datax[s][4]=v[s];
}
insert sub5=new insert();
sub5.creditnumber=creditnumber;
sub5.style=style;
sub5.data=datax;
sub5.datanumber=datanumber;
sub5.makedata(db,tab);
}
for(s=1;s<dicnumber+1;s++){
System.out.println("r"+s+","+dic[s]);
}
}
}
package air3;
import java.sql.*;
Connection dbx;
Statement stx;
String sqx;
ResultSet rsx;
int creditnumber;
String[] credit=new String[50];
String[] style=new String[50];
int[] strlong=new int[50];
void makedata(String db,String tab){
String str;
str="";
int s;
for(s=1;s<creditnumber;s++){
if(style[s].equals("INTEGER"))str=str+credit[s]+" "+style[s]+",";
if(style[s].equals("VARCHAR"))str=str+credit[s]+" "+style[s]+"("+strlong[s]+"),";
}
s=creditnumber;
if(style[s].equals("INTEGER"))str=str+credit[s]+" "+style[s];
if(style[s].equals("VARCHAR"))str=str+credit[s]+" "+style[s]+"("+strlong[s]+")";
String url = "jdbc:h2:"+db+";create=true";
String usr = "";
String pwd = "";
try{
Class.forName("org.h2.Driver");
dbx = DriverManager.getConnection(url, usr, pwd);
stx = dbx.createStatement();
String sqx = "CREATE TABLE " +tab+"("+str+")";
stx.executeUpdate(sqx);
} catch (Exception ex) { ex.printStackTrace();}
}
}
package air3;
import java.sql.*;
import java.io.*;
class insert {
Connection dbx;
Statement stx;
String sqx;
ResultSet rsx;
String[] style=new String[50];
int creditnumber;
String[][] data=new String[5000][50];
int datanumber;
int p;
void makedata(String db,String tab) {
String str;
int s,sx;
for(p=1;p<datanumber+1;p++){
str="";
for(sx=1;sx<creditnumber;sx++){
if(style[sx].equals("VARCHAR"))str=str+change(data[p][sx])+",";
if(style[sx].equals("INTEGER"))str=str+data[p][sx]+",";
}
sx=creditnumber;
if(style[sx].equals("VARCHAR"))str=str+change(data[p][sx]);
if(style[sx].equals("INTEGER"))str=str+data[p][sx];
String url = "jdbc:h2:"+db+";create=true";
String usr = "";
String pwd = "";
try{
Class.forName("org.h2.Driver");
dbx = DriverManager.getConnection(url, usr, pwd);
stx = dbx.createStatement();
String [[sql]] = "INSERT INTO "+tab+" VALUES("+str+")";
int num = stx.executeUpdate(sql);
stx.close();
} catch (Exception ex) { ex.printStackTrace();}
}
}
String change(String str){
String str1;
str1="'"+str+"'";
return str1;
}
}
最終更新:2015年08月21日 19:41