アットウィキロゴ

p082103

package wp;
 
 
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import tool.*;
 
public class pro {
 
  int s,datanumber;
  String[] data=new String[50000];
     String[] credit=new String[50000];
 
       String[] unit=new String[50000];
       String[] v=new String[50000];
     int number;
 
      String[] year=new String[50000];
     String[] month=new String[50000];
      String[] cou=new String[50000];
        String[] code=new String[50000];
      String[] bus=new String[50000];
     String[] mono=new String[50000];
 
 
 
      String exs;
         String[] dic_mono=new String[5000];
        String[] dic_bus=new String[5000];
      String[] dic_cou=new String[5000];
      int number_cou;  
 
        String[] code_cou=new String[50000];
        String[] code_unit=new String[50000];
        String[] code_credit=new String[50000];
 
         int creditnumber;
String[] creditp=new String[50];
String[] style=new String[50];
int[] strlong=new int[50];
     String[][] datax=new String[500000][10];
 
    public static void main(String[] args) {
        pro t=new pro();
    }
 
    pro(){
 
         creditnumber=7;
        creditp[1]="year";
        creditp[2]="month";
        creditp[3]="country";
        creditp[4]="credit";
        creditp[5]="bus";
        creditp[6]="unit";
        creditp[7]="value"; 
        style[1]="INTEGER";
        style[2]="INTEGER";
        style[3]="VARCHAR";
        style[4]="VARCHAR";
       style[5]="VARCHAR";
        style[6]="VARCHAR";
        style[7]="VARCHAR";
 
        strlong[3]=20;
        strlong[4]=20;
   strlong[5]=20;
        strlong[6]=20;
           strlong[7]=20;
 
        String db,tab;
 
 
 
 
         db="trade";
        tab="trade";
 
 
        table sub7=new table();
        sub7.credit=creditp;
        sub7.creditnumber=creditnumber;
        sub7.style=style;
        sub7.strlong=strlong;
        sub7.makedata(db,tab);
 
 
 
        int tr;
        number=0;
        number_cou=0;
 
     for(tr=1;tr<19;tr++){
 
        readfile sub=new readfile();
        sub.makedata("gdata/"+tr+".txt","UTF-8");
        data=sub.data;
        datanumber=sub.datanumber;
 
        System.out.println(tr);
 
 
        for(s=1;s<datanumber+1;s++){
        catchword sub2=new catchword();
        year[s]=sub2.makedata(data[s],"year");
        month[s]=sub2.makedata(data[s],"month"); 
        cou[s]=sub2.makedata(data[s],"country");    
        bus[s]=sub2.makedata(data[s],"bus");
        mono[s]=sub2.makedata(data[s],"mono");
        credit[s]=sub2.makedata(data[s],"credit");
        unit[s]=sub2.makedata(data[s],"unit");
        v[s]=sub2.makedata(data[s],"value");
        }
 
        int sx,j,h;
 
 
        for(s=1;s<datanumber+1;s++){
         h=0;
        for(sx=1;sx<number+1;sx++){
        j=0;
        if(mono[s].equals(dic_mono[sx]))j=j+1;
         if(bus[s].equals(dic_bus[sx]))j=j+1;
        if(j==2)h=100;
        }    
        if(h<50)number=number+1;
        if(h<50)dic_bus[number]=bus[s];
        if(h<50)dic_mono[number]=mono[s];
        }
 
 
        for(s=1;s<datanumber+1;s++){
        for(sx=1;sx<number+1;sx++){
        j=0;
        if(mono[s].equals(dic_mono[sx]))j=j+1;
         if(bus[s].equals(dic_bus[sx]))j=j+1;
        if(j==2)code[s]="m"+sx;
        }    
        }
 
 
        for(s=1;s<datanumber+1;s++){
         h=0;
        for(sx=1;sx<number_cou+1;sx++){
 
        if(cou[s].equals(dic_cou[sx]))h=100;
        }    
        if(h<50)number_cou=number_cou+1;
        if(h<50)dic_cou[number_cou]=cou[s];
        }
 
 
        for(s=1;s<datanumber+1;s++){
        for(sx=1;sx<number_cou+1;sx++){
        if(cou[s].equals(dic_cou[sx]))code_cou[s]="c"+sx;
        }    
        }
 
 
        for(s=1;s<datanumber+1;s++){
 
        if(credit[s].equals("輸出"))code_credit[s]="ex";   
        if(credit[s].equals("輸入"))code_credit[s]="im";
        }
 
        for(s=1;s<datanumber+1;s++){
        if(unit[s].equals("数量"))code_unit[s]="q";   
        if(unit[s].equals("金額"))code_unit[s]="v";
        }
 
 
          for(s=1;s<datanumber+1;s++){
 
        datax[s][1]=""+year[s];
        datax[s][3]=""+code_cou[s];
        datax[s][2]=""+month[s];
        datax[s][4]=""+code_credit[s];
        datax[s][5]=""+code[s];
        datax[s][6]=""+code_unit[s];
        datax[s][7]=""+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<number+1;s++){
     System.out.println("m"+s+","+dic_bus[s]+","+dic_mono[s]);
 
     }  
 
 
     for(s=1;s<number_cou+1;s++){
     System.out.println("c"+s+","+dic_cou[s]);
 
     }  
 
 
 
 
 
 
    }
 
 
 
 
}
 
 
 
 
 
package wp;
 
 
import java.sql.*; 
 
public class table{
 
    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 wp;
 
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日 13:26