//这段程序编译通过
import com.microsoft.jdbc.sqlserver.*;
public class test
{
public static void main()
{
System.out.println("hello");
SQLServerDriver x;
//Class.forName("SQLServerDriver");
}
};
//但是,这段程序通不过
//以下是出错信息:
/*test.java:8: 未报告的异常 java.lang.ClassNotFoundException;必须对其进行捕捉或声
明以便抛出
Class.forName("SQLServerDriver");
^
1 错误
*/
import com.microsoft.jdbc.sqlserver.*;
public class test
{
public static void main()
{
System.out.println("hello");
//SQLServerDriver x;
Class.forName("SQLServerDriver");
}
};
import com.microsoft.jdbc.sqlserver.*;
public class test
{
public static void main()
{
System.out.println("hello");
SQLServerDriver x;
//Class.forName("SQLServerDriver");
}
};
//但是,这段程序通不过
//以下是出错信息:
/*test.java:8: 未报告的异常 java.lang.ClassNotFoundException;必须对其进行捕捉或声
明以便抛出
Class.forName("SQLServerDriver");
^
1 错误
*/
import com.microsoft.jdbc.sqlserver.*;
public class test
{
public static void main()
{
System.out.println("hello");
//SQLServerDriver x;
Class.forName("SQLServerDriver");
}
};
public class test
{
public static void main()
{
System.out.println("hello");
//SQLServerDriver x;
try{
Class.forName("SQLServerDriver");
}catch(Exception e){}
}
};或
public class test
{
public static void main() throws Exception
{
System.out.println("hello");
//SQLServerDriver x;
Class.forName("SQLServerDriver");
}
};因为这是个必须捕获的异常类。请学点基础只是好吗?