package h2;
public class pro {
int creditnumber;
String[] creditp=new String[50];
String[] style=new String[50];
int[] strlong=new int[50];
int datanumber;
String[][] datax=new String[500][10];
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[2]=10;
String db,tab;
db="inv";
tab="inv99";
table sub7=new table();
sub7.credit=creditp;
sub7.creditnumber=creditnumber;
sub7.style=style;
sub7.strlong=strlong;
sub7.makedata(db,tab);
int s;
datanumber=5;
for(s=1;s<datanumber+1;s++){
datax[s][1]=""+s;
datax[s][2]=""+(s+50);
datax[s][3]="a"+s;
datax[s][4]="b"+(s+50);
}
insert sub5=new insert();
sub5.creditnumber=creditnumber;
sub5.style=style;
sub5.data=datax;
sub5.datanumber=datanumber;
sub5.makedata(db,tab);
String[] v=new String[50];
select cc=new select();
cc.makedata(db,tab,"a2");
v=cc.v;
System.out.println(v[1]);
}
}
package h2;
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 h2;
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 h2;
import java.sql.*;
class select{
Connection dbx;
Statement stx;
String sqx;
ResultSet rsx;
int key;
String word;
int sx,number;
int[] year=new int[5000];
String[] v=new String[5000];
int[] month=new int[500];
void makedata(String db,String tab,String cr1){
String url = "jdbc:h2:"+db+";create=true";
String usr = "";
String pwd = "";
try
{
Class.forName("org.h2.Driver");
dbx = DriverManager.getConnection(url, usr, pwd);
} catch (Exception ex) { ex.printStackTrace();}
sx=0;
try {
stx = dbx.createStatement();
sqx="select * from "+tab+" WHERE bus="+change(cr1);
rsx = stx.executeQuery(sqx);
if (rsx != null) {
while (rsx.next()) {
sx=sx+1;
v[sx]= rsx.getString("value");
year[sx]=rsx.getInt("year");
month[sx]=rsx.getInt("month");
}
}
number=sx;
rsx.close();
stx.close();
dbx.close();
} catch (Exception ex) {ex.printStackTrace();}
}
String change(String word){
String e;
e="'"+word+"'";
return e;
}
}
最終更新:2016年05月15日 04:40