JDBC 액세스 Excel 테이블

1532 단어 면접
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement;
public class ExcelReader {
    public static void main( String[] args ) {
        Connection c = null;
        Statement stmnt = null;
        try {
            Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");             c = DriverManager.getConnection("jdbc:odbc:driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=c:\\l_f3.201004.xlsx");//데이터 소스 설정 안 함
           //c = DriverManager.getConnection( "jdbc:odbc:Book1", "", "");
            stmnt = c.createStatement();
//sc 조회할 sheet 이름입니다. 형식 주의[sc$]
            String query = "SELECT * FROM [sc$] ";
            ResultSet rs = stmnt.executeQuery( query );             int i = 0; while(rs.next()) {i++; System.out.println(rs.getString("사용자 도착 목록")+i);//사용자 도착 목록은 열 이름입니다.
            }
        }
        catch( Exception e ) {
            System.err.println( e );
        }
        finally {
            try {
                stmnt.close();
                c.close();
            }
            catch( Exception e ) {
                System.err.println( e );
            }
        }
    }
}
문서:
http://wenku.baidu.com/link?url=4qZyfZqsNhnDzmdXE2DhTZkOjLOZEz1IivG_FkaxLRu4nsMMdw8Fp_YyKq8MKyr9Wl7iWKhoJgsGqcPYCVyL_09ecEyZiIpO_EavwNfnkjy

좋은 웹페이지 즐겨찾기