java采用POI读取excel的问题(在线)
我从网上拷了下面的代码 运行时出错说
E:\> javac POITest.java
Note: POITest.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
(jdk1.4 POI)
代码如下
import java.io.FileInputStream;
import
java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import
java.sql.SQLException;
import java.sql.Statement;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
public class POITest {
public static Connection conn = null;
public static Statement stmt = null;
public static boolean connectDB2() {
try {
Class.forName( "oracle.jdbc.driver.OracleDriver ");
conn = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:CF132 ", "CHENYU ", "123456 ");
stmt = conn.createStatement();
}
//捕获加载驱动程序异常
catch (
ClassNotFoundException cnfex) {
System.err.println( "装载JDBC驱动程序失败。 ");
cnfex.printStackTrace();
return false;
}
//捕获连接
数据库异常 catch (
SQLException sqlex) {
System.err.println( "无法连接数据库 ");
sqlex.printStackTrace();
//System.exit(1); // terminate program
return false;
}
return true;
}
public static boolean readExcelToDB2() {
POIFSFileSystem fs = null;
HSSFWorkbook wb = null;
try {
fs = new POIFSFileSystem(new FileInputStream( "e:\\test.xls "));
wb = new HSSFWorkbook(fs);
} catch (
IOException e) {
e.printStackTrace();
return false;
}
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = null;
HSSFCell cell = null;