日期:2014-05-17  浏览次数:20712 次

怎么通过javabean调用这段代码
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.StringTokenizer;
import list.ConnOracle;

class FileOperate {
private static Statement connc;
private static Connection connOrac;
  public static void main(String[] args) throws IOException {
 
  try {
  Class.forName("com.mysql.jdbc.Driver").newInstance(); 
  connOrac = DriverManager.getConnection("jdbc:mysql://localhost/ip?user=root&password=1314521&useUnicode=true&characterEncoding=gb2312");
  connc=connOrac.createStatement();
  System.out.println("ok1");
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   
   
  } catch (Exception e) {
  e.printStackTrace();
  }
 
 
  BufferedReader reader = new BufferedReader(new FileReader("D:\\hello.txt"));
  String line,ans = null;
  try {
  while((line=reader.readLine())!=null)
  if(line.contains("TTL")){
   
   
  ans = search(line);
  // System.out.println(line);
  if(!ans.equals("")){
  StringTokenizer st = new StringTokenizer(ans);
  //按记录一条一条输出
  while(st.hasMoreTokens()){
  String number = st.nextToken();
  String name = st.nextToken();
  String door = st.nextToken();
  String number2 = st.nextToken();
  String name2 = st.nextToken();
  String door2 = st.nextToken();
   
   
  System.out.println(name);
   
 String sql="SELECT country , LOCAL FROM iptable WHERE StartIpText = '"+name+"' " ;
   
   
   
  try {
  ResultSet rs = connc.executeQuery(sql);
  // int i = 0;
  // int rowCount = rs.getRow();//首先将指针移动到最后一条记录,获得总记录数
  String[] arr=new String[10000];
  int i=0;  
  String no;
 
  while(rs.next() ){
   
  String country = rs.getString("country");
   
  String Local = rs.getString("Local");
  System.out.println(country);
  System.out.println(Local); 
  }
   
   
   
  }catch(Exception e){
  e.printStackTrace();
 
  }