import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class createIndex {
public static void main(String[] args) {
try {
FileWriter out = new FileWriter("C://createIndex.sql");
File file = new File("f://KYOGOKU");
String files[];
files = file.list();
for (int fileNo = 0; fileNo < files.length; fileNo++) {
if(!files[fileNo].endsWith(".xls")){
continue;
}
File f = new File("f://KYOGOKU//" + files[fileNo]);
Workbook wb;
wb = Workbook.getWorkbook(f);
Sheet[] sheets = wb.getSheets();
int indexColumnCount;
for(int i=0; i <sheets.length;i++){
String tableName = sheets[i].getCell(0, 3).getContents();
int indexNo = 1;
for(int col=8;col<sheets[i].getColumns();col++){
indexColumnCount = 0;
String strIndex = "create index "+tableName+"_INDEX"+indexNo+" on "+tableName+" (";
for(int row=8;row<sheets[i].getRows();row++){
if(sheets[i].getCell(col, row).getContents()!=""){
strIndex += sheets[i].getCell(2, row).getContents();
strIndex += ", ";
indexColumnCount++;
}
}
if(indexColumnCount == 0){
strIndex = "";
}else{
strIndex = strIndex.substring(0, strIndex.length() - 2);
strIndex += ");";
strIndex += "/r/n";
strIndex += "//";
strIndex += "/r/n";
}
System.out.println(strIndex);
if(strIndex!=""){
out.write(strIndex);
}
indexNo++;
}
}
}
out.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (BiffException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}