没有抛出异常,在Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); 
//设置数据库连接字符串 
 strCon ="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=dboil" ; 
//连接数据库 
 sqlCon = java.sql.DriverManager.getConnection(strCon,"sa","sa"); 
加上
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); 
//设置数据库连接字符串 
 strCon ="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=dboil" ; 
//连接数据库 
 sqlCon = java.sql.DriverManager.getConnection(strCon,"sa","sa"); }catch(Exception e){}

解决方案 »

  1.   

    Class.forName()处没有声明捕获java.lang.ClassNotFoundException异常,
    其它几处没有声明捕获java.sql.SQLException异常。改写为
    try{
     ...
     ...
    }catch(ClassNotFoundException e){
      // 在这里写没有找到driver时的处理
    }catch(java.sql.SQLException sqle){
      // 在这里写SQL异常的处理
    }
      

  2.   

    加入后:D:\tomcat-4.1.27\jakarta-tomcat-4.1.27\work\Standalone\localhost\dwx\Jsp\MWatch_jsp.java:29: variable sqlCon might not have been initialized
     sqlStmt = sqlCon.createStatement(); 
               ^
    D:\tomcat-4.1.27\jakarta-tomcat-4.1.27\work\Standalone\localhost\dwx\Jsp\MWatch_jsp.java:29: unreported exception java.sql.SQLException; must be caught or declared to be thrown
     sqlStmt = sqlCon.createStatement(); 
                     ^
    D:\tomcat-4.1.27\jakarta-tomcat-4.1.27\work\Standalone\localhost\dwx\Jsp\MWatch_jsp.java:44: unreported exception java.sql.SQLException; must be caught or declared to be thrown
     sqlRst= sqlStmt.executeQuery(strSQL);
                    ^
    D:\tomcat-4.1.27\jakarta-tomcat-4.1.27\work\Standalone\localhost\dwx\Jsp\MWatch_jsp.java:45: unreported exception java.sql.SQLException; must be caught or declared to be thrown
    if(sqlRst.next())
             ^
    4 errors