アットウィキロゴ

せぇctb

package h2;
 
import java.io.*;
 
public class pro {
 
    String[] credit=new String[20];
    String[] type=new String[20];
    int creditnumber;
      String[][] data=new String[50000][20];
    int s,sx,datanumber;
 
    public static void main(String[] args) {
        pro test=new pro();
    }
    pro(){
 
        creditnumber=6;
        credit[1]="WYEAR";
         credit[2]="WMONTH";
         credit[3]="WDAY";
        credit[4]="RANK";
         credit[5]="ARTIST";
         credit[6]="TITLE";
          type[1]="int";
         type[2]="int";
         type[3]="int";
        type[4]="int";
         type[5]="string";
         type[6]="string";
 
 
        select sub=new select();
        sub.credit=credit;
        sub.creditnumber=creditnumber;
        sub.type=type;
        sub.makedata("sap","sap");
        datanumber=sub.datanumber;
        data=sub.data;
 
 
 
        writefile("ren.csv");
 
 
    }
void writefile(String file){ 
 
try{ 
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file))); 
 
for(s=1;s<datanumber+1;s++){ 
for(sx=1;sx<creditnumber;sx++){ 
pw.print(data[s][sx]); 
pw.print(",");
} 
sx=creditnumber;
pw.println(data[s][sx]); 
}   
 
 
System.out.println("ファイルに書きこみました。"); 
pw.close(); 
} catch(IOException ep){ System.out.println("入出力エラーです。"); } 
 
 
} 
 
 
}
 
 
package h2;
 
import java.sql.*; 
 
class select{ 
 
Connection dbx;   
Statement stx;   
String sqx; 
ResultSet  rsx; 
 
int key; 
String word;
int sx;
  String[] credit=new String[20];
    String[] type=new String[20];
    int creditnumber;
    int tx;
     String[][] data=new String[50000][20];
    int datanumber;
 
 
void makedata(String db,String tab){ 
 
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();} 
 
tx=0;
try {   
stx = dbx.createStatement(); 
sqx="select * from "+tab;   
rsx = stx.executeQuery(sqx); 
if (rsx != null) { 
while (rsx.next()) { 
tx=tx+1;
for(sx=1;sx<creditnumber+1;sx++){
String x1;
x1="";
if(type[sx].equals("int"))x1 =""+rsx.getInt(credit[sx]);
if(type[sx].equals("string"))x1 =rsx.getString(credit[sx]);
data[tx][sx]=x1;
}
} 
} 
 
datanumber=tx;
 
rsx.close(); 
stx.close(); 
dbx.close(); 
 
} catch (Exception ex) {ex.printStackTrace();} 
 
 
 
 
} 
 
String change(String word){
String e;
e="'"+word+"'";
return e;    
}    
 
 
 
}
 
最終更新:2013年12月11日 03:11