JAVA获得股票数据大全(二)

2014-11-24 08:22:15 · 作者: · 浏览: 1
leep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

public List getFailureList() {
return failureList;
}

public void setFailureList(List failureList) {
this.failureList = failureList;
}

public List getSuccessList() {
return successList;
}

public void setSuccessList(List successList) {
this.successList = successList;
}

}

2.将下载完的文件统一保存到数据库工具类
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class CSVUtitl {

private BufferedReader bufferedreader = null;
private List list = new ArrayList();

public CSVUtitl(){

}
public CSVUtitl(String filename) throws IOException{

bufferedreader = new BufferedReader(new FileReader(filename));
String stemp;
while((stemp = bufferedreader.readLine()) != null){
list.add(stemp);
}
}
public List getList() throws IOException {

return list;
}
// 得到csv文件的行数
public int getRowNum(){

return list.size();
}

//得到csv文件的列数
public int getColNum(){

if(!list.toString().equals("[]")) {

//csv文件中,每列之间的是用','来分隔的
if(list.get(0).toString().contains(",")) {
return list.get(0).toString().split(",").length;
}else if(list.get(0).toString().trim().length() != 0) {
return 1;
}else{
return 0;
}
}else{
return 0;
}
}

//取得指定行的值
public String getRow(int index) {

if (this.list.size() != 0)
return (String) list.get(index);
else
return null;
}

//取得指定列的值
public String getCol(int index){

if (this.getColNum() == 0){
return null;
}

StringBuffer scol = new StringBuffer();
String temp = null;
int colnum = this.getColNum();

if (colnum > 1){
for (Iterator it = list.iterator(); it.hasNext();) {
temp = it.next().toString();
scol = scol.append(temp.split(",")[index] + ",");
}
}else{
for (Iterator it = list.iterator(); it.hasNext();) {
temp = it.next().toString();
scol = scol.append(temp + ",");
}
}
String str=new String(scol.toString());
str = str.substring(0, str.length() - 1);
return str;
}

//取得指定行,指定列的值
public String getString(int row, int col) {

String temp = null;
int colnum = this.getColNum();
if(colnum > 1){
temp = list.get(row).toString().split(",")[col];
}else if(colnum == 1) {
temp = list.get(row).toString();
}else{
temp = null;
}
return temp;
}


public void CsvClose() throws IOException {
this.bufferedreader.close();
}

public void run(String filename) throws IOException {

CSVUtitl cu = new CSVUtitl(filename);

for(int i=0;i String SSCCTag = formatData(cu.getString(i,1));//得到第i行.第一列的数据.
String SiteName = formatData(cu.getString(i,2));//得到第i行.第二列的数据.
String StationId= formatData(cu.getString(i,3));

//将数据保存到数据库
... ...
... ...
... ...
}
cu.CsvClose();
}

pub