码家

Web Platform, Cloud and Mobile Application Development

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

package extractors;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class ExtractorDA {
 public static void main(String args[]) {        
  ExtractorDA t = new ExtractorDA();
  String str = t.getTXT();
  String[] s = str.split("\\.");
  System.out.println(s.length);
  System.out.println(str);
  t.fromatFile(s);
 }

 public String getTXT() {

  String JDriver = "com.mysql.jdbc.Driver";
  String conURL = "jdbc:mysql://localhost:3306/extractor";
  
  String result="";
  
  try {
   Class.forName(JDriver);
  } catch (ClassNotFoundException cnf_e) {
   System.out.println("Driver Not Found: " + cnf_e);
  }

  try {
   Connection con = DriverManager
     .getConnection(conURL, "root", "root");
   Statement s = con.createStatement();
   ResultSet rs = s.executeQuery("select * from extractor_txt;");
   while (rs.next()) {
    result=rs.getString("txt");
   }
   s.close();
   con.close();
  } catch (SQLException sql_e) {
   System.out.println(sql_e);
  }
  
  return result;
 }
 
 public void fromatFile(String[] list) {
  try {
   for (int i = 0; i < list.length; i++) {
    String one = (String) list[i];
    String[] contents = one.split(",");
    System.out.println("Employee->" + (i + 1));
    System.out.println("Employee Name:" + contents[0]);
    System.out.println("Employee ID:" + contents[1]);
    System.out.println("Employee Department:" + contents[2]);
   }
  } catch (Exception ex) {
   ex.printStackTrace();
  }
 }
}

posted on 2011-10-17 10:51  海山  阅读(206)  评论(0)    收藏  举报