Home > 我就是未分类 > excel数据导入

excel数据导入

September 16th, 2004
import=\”java.sql.*\” 

String dbName = \”sun.jdbc.odbc.JdbcOdbcDriver\”;
  String url = \”jdbc:odbc:tmp\”;//odbc源
    Connection con=null;
    Statement stmt=null;
    ResultSet rs=null; 

    try {
          Class.forName(dbName);
          /**建立数据库连接*/ 
         }
    catch(ClassNotFoundException e)
        {
          System.out.print(\”加载数据库驱动程序错误:\”); 
        }
     try{
           con = DriverManager.getConnection(url,\”\”,\”\”);
           stmt=con.createStatement();
           String sql=\”select * from [Sheet1$]\”;//Sheet1为EXCEL表中的页名
           rs=stmt.executeQuery(sql); 

           while(rs.next())
                  {
                      System.out.println(rs.getString(1)+
                      \” \”+ rs.getString(2)+\” \”+
                       rs.getString(3));
                   } 

        }
        catch(Exception e1)
          { 
            System.out.println(e1.toString());
           }
       try{
              rs.close();
              stmt.close();
              con.close();
          }
          catch(Exception e){}
    

我就是未分类

  1. No comments yet.
  1. No trackbacks yet.