package maimai;
import tool.*;
import java.io.File;
public class pro {
String[] data=new String[50000];
int s,sx,datanumber,tx;
int[] year=new int[50000];
String[] month=new String[5000];
String[] credit=new String[5000];
String[] bus=new String[5000];
String[] work=new String[5000];
double[] v=new double[50000];
int number_month;
int number_credit;
int number_work,number_bus;
String[] dic_month=new String[500];
String[] dic_credit=new String[500];
String[] dic_work=new String[500];
String[] dic_bus=new String[500];
int number;
int creditnumber;
String[] creditp=new String[50];
String[] style=new String[50];
int[] strlong=new int[50];
public static void main(String[] args) {
pro te=new pro();
}
pro(){
creditnumber=4;
creditp[1]="year";
creditp[2]="month";
creditp[3]="bus";
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="sev";
tab="sev";
table sub7=new table();
sub7.credit=creditp;
sub7.creditnumber=creditnumber;
sub7.style=style;
sub7.strlong=strlong;
sub7.makedata(db,tab);
memo sub2=new memo();
sub2.creditnumber=creditnumber;
sub2.style=style;
sub2.makedata(db,tab);
}
}
package maimai;
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 maimai;
import tool.*;
public class memo {
String[] data=new String[50000];
int s,sx,datanumber,tx;
String[] year=new String[50000];
String[] month=new String[5000];
String[] credit=new String[5000];
String[] bus=new String[5000];
String[] v=new String[5000];
double[] v3=new double[50000];
int number_month;
int number_credit;
int number_work,number_bus;
double[] vs=new double[50000];
String[] subdata=new String[50000];
int[] ys=new int[5000];
int number;
String[] dic_month=new String[500];
String[] dic_credit=new String[500];
String[] dic_work=new String[500];
String[] dic_bus=new String[500];
int creditnumber;
String[][] datax=new String[50000][10];
String[] style=new String[50];
void makedata(String db,String tab){
sx=0;
readfile sub=new readfile();
sub.makedata("ren.txt","UTF-8");
data=sub.data;
datanumber=sub.datanumber;
String str;
int h;
for(s=1;s<datanumber+1;s++){
catchword sub52=new catchword();
str=sub52.makedata(data[s],"date");
h=0;
if(str.indexOf("月")>-1)h=h+1;
if(str.indexOf("期")<0)h=h+1;
if(h==2)sx=sx+1;
if(h==2)subdata[sx]=data[s];
}
datanumber=sx;
for(s=1;s<datanumber+1;s++){
catchword sub2=new catchword();
str=sub2.makedata(subdata[s],"date");
int p1=str.indexOf("年");
int p2=str.indexOf("月");
year[s]=str.substring(0,p1);
month[s]=str.substring(p1+1,p2);
bus[s]= sub2.makedata(subdata[s],"code_bus");
v[s]=sub2.makedata(subdata[s],"value");
}
for(s=1;s<datanumber+1;s++){
datax[s][1]=year[s];
datax[s][2]=month[s];
datax[s][3]=bus[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);
}
double num(String str){
double nx;
nx=0;
try{
nx=Double.parseDouble(str);
}catch (Exception e) {}
return nx;
}
}
package maimai;
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年03月31日 03:45