我觉得不应该加finally,如果前面的try抛出异常的话,就不会有stmt和con的定义了!
我觉得是这样的!

解决方案 »

  1.   

    1、Class类中的原代码:
        public static Class forName(String className) 
                    throws ClassNotFoundException {
            
        }
    它只可能会抛出ClassNotFoundException,而不会抛出SQLException,所以编译你都通不过!只需要捕获ClassNotFoundException就可以了!2、你的con及stmt在声明的只是简单的
       Connection con;
       只不过声明了一个变量,它实际上并没有被指向一个类,所以报错,
      

  2.   

    finally{...}中的语句一定会执行,
    但你的con或stmt并不一定可以成功指向一个类,
    如果这样的话就会产生错误了。
      

  3.   

    这种错误用金山词霸翻译看看
    exception java.sql.SQLException is never thrown in body of corresponding try statement
    SQLException 永远都不会抛出variable stmt might not have been initialized
    变量没有初始化
    public void execute(String SQLCommand){
    url+=dbName;
    Connection con;
    Statement stmt;
    改为
    public void execute(String SQLCommand){
    url+=dbName;
    Connection con=null;
    Statement stmt=null;