アットウィキロゴ

じゃヴぁがめ0125

import java.net.*;
import java.io.*;
import java.util.*;
import java.sql.*;

public class game0125{

String data[]=new String[10000];
int m,mx,n,num;
String article[]=new String[100];  
String name;

Connection db = null;
Statement  st = null;
ResultSet  rs = null;  
String url = "jdbc:derby:db;create=true";  
String usr = "";
String pwd = "";    

public static void main(String[] args){
        
new game0125();
}

game0125(){

name="http://saayaworld.blog70.fc2.com/?xml";

getdata(name);

makearticle(data,num);

createtable("hell101","(item long varchar)");

insertdata("hell101",article[5]);

select("item","hell101");
  
}

void insertdata(String tablename,String newdata){;
Connection dbx;
Statement  stx;
String sqx;

sqx="insert into  " +tablename+ " values('";
sqx=sqx+newdata;
sqx=sqx+"')";
try {
dbx = DriverManager.getConnection(url, usr, pwd);
stx = dbx.createStatement();
stx.executeUpdate(sqx);
stx.close();
dbx.close();
} catch (Exception ex) {ex.printStackTrace();}

}
void createtable(String tablename,String aa){
Connection dbx;
Statement  stx;
String sqx;
sqx="create table "+tablename+aa;
try {
dbx = DriverManager.getConnection(url, usr, pwd);
stx = dbx.createStatement();
stx.executeUpdate(sqx);
stx.close();
dbx.close();
} catch (Exception ex) {ex.printStackTrace();}
}


void select(String x,String tablename){
Connection dbx;
Statement  stx;
ResultSet  rsx;
String sqx;
try {
dbx = DriverManager.getConnection(url, usr, pwd);
stx = dbx.createStatement();
sqx="select * from ";
sqx=sqx+tablename;
rsx = stx.executeQuery(sqx);
if (rsx != null) {
while (rsx.next()) {
String item = rsx.getString(x);
System.out.println(item);
}
}
      rsx.close();
      stx.close();
      dbx.close();
} catch (Exception ex) {ex.printStackTrace();}
}

void makearticle(String[] data,int num){
int m;
int n1,n2;
int plan[]=new int[1000];
m=0;
for(n=0;n<num;n++){
if(data[n].indexOf("item")>-1)m=m+1;
if(data[n].indexOf("item")>-1)plan[m]=n;  
}
mx=m/2;
for(m=1;m<mx+1;m++){
n1=plan[2*m-1];
n2=plan[2*m];
article[m]="";
for(n=n1;n<n2+1;n++){
article[m]=article[m]+data[n];
}
}

}

void getdata(String name){
try{
        URL url = new URL(name);

        HttpURLConnection con = (HttpURLConnection)url.openConnection();
        con.setRequestMethod("GET");
        con.connect();

        BufferedReader reader =
            new BufferedReader(new InputStreamReader(con.getInputStream(),"UTF-8"));
n=0;
        while (true){
            String line = reader.readLine();
            if ( line == null ){
                break;
            }
data[n]=line;
n=n+1;
num=n;
        }

        reader.close();
        con.disconnect();
}
catch(Exception e) { System.err.println(e); }
}




}
最終更新:2011年03月25日 21:12