void xsxinxiluru(String sl){
     Connection xlscon;
     Statement xlssql;
     ResultSet xlsrs;    
     try{
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     }
     catch(ClassNotFoundException e){System.out.print(e);}    
     try{      
       xlscon=DriverManager.getConnection("jdbc:odbc:kaoshi","","");  
       xlscon.setAutoCommit(false);   
       //String xlsxuesheng=request.getParameter(sl);
       byte b[]=sl.getBytes("ISO-8859-1");
       sl=new String(b);
       jxl.Workbook workbook=jxl.Workbook.getWorkbook(new File(sl));
       Sheet sheet = workbook.getSheet(0);
       Cell cell = null;      
       int rowCount=sheet.getRows();
       //int columnCount=sheet.getColumns();
       for (int i = 1; i <rowCount; i++){
          //for (int j = 0; j <columnCount; j++){
          //  cell=sheet.getCell(j, i);
          //  if(cell.getType()==CellType.NUMBER){
          //    out.print(((NumberCell)cell).getValue());
          //  }
          //  else if(cell.getType()==CellType.DATE){
          //    out.print(((DateCell)cell).getDate());
          //  }
          //  else{
          //    out.print(cell.getContents());
          // }        
          //}
         cell=sheet.getCell(0,i);
         int xlsnumber=Integer.parseInt(cell.getContents());
         cell=sheet.getCell(1,i);
         String xlsname=cell.getContents();
         cell=sheet.getCell(2,i);
         String xlsspecialty=cell.getContents();
         cell=sheet.getCell(3,i);
         String xlsclass=cell.getContents(); 
         //Statement xlssql;       
         String xscr="INSERT INTO student (number,name,specialty,class) VALUES"+"("+"'"+xlsnumber+"','"+xlsname+"','"+xlsspecialty+"','"+xlsclass+"')" ;       
         xlssql=xlscon.createStatement();
         xlssql.executeUpdate(xscr); 
         xlssql.close();    
       }
       xlscon.commit();
       workbook.close();
       xlscon.close();
}

     catch(Exception e1){//System.out.print(e1);
      try{xlscon.rollback();}
       catch(SQLException e2){}
       //catch(Exception e3){}  
     }
  
   }%>
<html>
  <head> 
    <title>学生信息录入</title>
  </head>
  <body>
    <% 
String xlsxuesheng=request.getParameter("lujin");
xsxinxiluru(xlsxuesheng);
%>      
  </body>
</html>显示说The local variable xlscon may not have been initialized
怎么解决呀

解决方案 »

  1.   

    Connection xlscon = null;
    Statement xlssql = null;
    ResultSet xlsrs = null;
    这样就好了    
      

  2.   

    这个我试过了,虽然不报错了,但链接数据库速度奇慢,每次SQLSERVER都显示链接超时
      

  3.   

    try{
        Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
    //加载并注册驱动程序
    }catch(ClassNotFoundException e)
    {
    e.printStackTrace();
    }catch(InstantiationException e)
    {
    e.printStackTrace();
    }catch(IllegalAccessException e)
    {
    e.printStackTrace();
    }
    String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=stu";
    String user="sa";
    String password="";
    try{
    Connection con = DriverManager.getConnection(url,user,password);//搜索驱动,创建一个 Connection 对象
    }用这个的前提是要有直连用的三个jar文件,偶忘记叫什么名字了,你去搜一下Microsoft SQL Server 2000 Driver for JDBC这个就应该可以找到