アットウィキロゴ

コード8

package op;
 
import tool.*;
 import java.io.*;
public class pro {
 
    int s,datanumber;
    String[] data=new String[500000];
     String[] bus=new String[5000];
     String[] com=new String[5000];
     int[] code=new int[50000];
     String[] dic_bus=new String[50000];
     String[] dic_com=new String[50000];
     String[] code_bus=new String[50000];
     String[] code_com=new String[50000];
     String[] month=new String[50000];
     String[] year=new String[50000];
     double[] v=new double[50000];
     double[] vs=new double[50000];
    String[] date=new String[50000];
     int number,number_com;
   int[] point=new int[1000];  
    public static void main(String[] args) {
        pro test=new pro();
    }
 
    pro(){
 
 
            int creditnumber;
String[] creditp=new String[50];
String[] style=new String[50];
int[] strlong=new int[50];
     String[][] datax=new String[500000][10];
 
 
 
       creditnumber=5;
        creditp[1]="year";
         creditp[2]="month";
         creditp[3]="bus";
        creditp[4]="oil";
        creditp[5]="value"; 
        style[1]="INTEGER";
        style[4]="VARCHAR";
       style[3]="VARCHAR";
         style[5]="VARCHAR";
        style[2]="INTEGER";
 
         strlong[4]=20;
strlong[3]=20;
        strlong[5]=20;
strlong[2]=20;
 
        String db,tab;
 
 
         db="oil";
        tab="oil";
 
 
 
        table sub7=new table();
        sub7.credit=creditp;
        sub7.creditnumber=creditnumber;
        sub7.style=style;
        sub7.strlong=strlong;
        sub7.makedata(db,tab);
 
 
 
 
        number=0;
        number_com=0;
 
          String file,str;
 
          int tr;
 
          for(tr=0;tr<65;tr++){
 
              file="gdata/"+tr+".txt";
           readx(file);
 
           double d;
           int y1,m1;
           String c;
 
         for(s=1;s<datanumber+1;s++){
         catchword sub=new catchword();
         bus[s]=sub.makedata(data[s],"bus");
         com[s]=sub.makedata(data[s],"mono");
         date[s]=sub.makedata(data[s],"date");;
         str=sub.makedata(data[s],"value");
         v[s]=num(str);
 
         }
 
            for(s=1;s<datanumber+1;s++){
            date[s]=date[s].replace("k.xls","");
            date[s]=date[s].replace("h2dii","");
            }
 
        for(s=1;s<datanumber+1;s++){
        year[s]=date[s].substring(0,4);
        month[s]="7"+date[s].substring(4,6);
        int n=numx(month[s]);
        month[s]=""+(n-700);
        }
 
 
    int h,sx;
         dic_bus[0]="";
         for(s=1;s<datanumber+1;s++){
         h=0;   
         for(sx=0;sx<number+1;sx++){
         if(bus[s].equals(dic_bus[sx]))h=100;
         } 
         if(h<50)number=number+1;
         if(h<50)dic_bus[number]=bus[s];
         }
 
 
         dic_com[0]="";
        for(s=1;s<datanumber+1;s++){
         h=0;   
         for(sx=0;sx<number_com+1;sx++){
         if(com[s].equals(dic_com[sx]))h=100;
         } 
         if(h<50)number_com=number_com+1;
         if(h<50)dic_com[number_com]=com[s];
         }
 
         for(s=1;s<datanumber+1;s++){
         code_com[s]="";
         for(sx=1;sx<number_com+1;sx++){
         if(com[s].equals(dic_com[sx]))code_com[s]="m"+sx;
         }}
 
 
 
         for(s=1;s<datanumber+1;s++){
         code_bus[s]="";
             for(sx=1;sx<number+1;sx++){
         if(bus[s].equals(dic_bus[sx]))code_bus[s]="b"+sx;
         }}
 
 
 
         sx=0;
          for(s=1;s<datanumber+1;s++){
       h=0;
       if(code_bus[s].length()<1)h=100;       
        if(code_com[s].length()<1)h=100; 
            if(h<60){
        sx=sx+1;
        datax[sx][1]=""+year[s];
        datax[sx][2]=""+month[s];
        datax[sx][3]=""+code_bus[s];
        datax[sx][4]=""+code_com[s];
        datax[sx][5]=""+v[s];
            }
            }
 
 
         datanumber=sx;
 
        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_com+1;s++){    
          System.out.println("m"+s+","+dic_com[s]);
    }
 
         for(s=1;s<number+1;s++){    
          System.out.println("b"+s+","+dic_bus[s]);
    }
 
 
 
 
 
 
 
 
 
    }
 
 
   int numx(String str){
    int nx;
    nx=0;
 try{
    nx=Integer.parseInt(str);
 }catch (Exception e) {}
 return nx;
 
}
 
 
double num(String str){
    double nx;
    nx=0;
 try{
    nx=Double.parseDouble(str);
 }catch (Exception e) {}
 return nx;
 
} 
 
 
 void readx(String file){
 
String str;
BufferedReader br;  
int s;
s=0;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));  
while((str = br.readLine()) != null) {  
s=s+1;
data[s]=str;  
}
br.close();
} catch (IOException e) {System.out.println(e);}  
 
datanumber=s;
 
} 
 
 
 
}
 
 
 
package op;
 
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;
}
}
 
 
 
package op;
 
 
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();} 
 
 
 
 
 
 
    }
}
 
最終更新:2015年08月25日 19:09