import java.io.*;import org.apache.poi.hssf.usermodel.*;import java.sql.*;public classtest3 {public static voidmain(String[] args) {
String driver= "com.mysql.jdbc.Driver";
String url= "jdbc:mysql://localhost:3306/test";
String user= "root";
String password= "root";
Connection conn= null;
PreparedStatement ps=null;
ResultSet rs=null;
FileInputStream inp=null;
HSSFWorkbook wb=null;try{
inp= new FileInputStream("E:/test3.xls");
wb= newHSSFWorkbook(inp);
HSSFSheet sheet= wb.getSheetAt(0);int coloumNum=sheet.getRow(0).getPhysicalNumberOfCells();int rowNum=sheet.getLastRowNum();
Class.forName(driver);
conn=DriverManager.getConnection(url,user,password);
String sqlInset= "select * from xls";
ps=conn.prepareStatement(sqlInset);
rs=ps.executeQuery();
String temp=null;boolean flag=false;for(int i=0;i<=rowNum;i++) {
HSSFRow row=sheet.getRow(i);
HSSFCell cell= row.getCell(0);
HSSFCell cell2= row.getCell(1);if(cell.getCellType()!=1) {
cell.setCellType(1);
}
temp=cell.getStringCellValue();
rs=ps.executeQuery();while(rs.next()) {if(temp.equals(rs.getString(1))) {
flag=true;
System.out.println(temp);break;
}
}if(flag) {
FileOutputStream oup= new FileOutputStream("E:/test3.xls");//写出流,让每次操作之后都写回磁盘
cell2.setCellType(1);//以字符串的方式写回
cell2.setCellValue("yes");//设置写回的值为yes
wb.write(oup);//通过HSSFWrokbook提供的函数写回到磁盘
oup.close();
flag=false;
}
}
rs.close();
ps.close();
conn.close();
wb.close();
inp.close();
}catch(Exception e) {
e.printStackTrace();
}
}
}