你在catch里面也应该写一个返回,
或者在最后面写也可以

解决方案 »

  1.   

    补充一下:
    你在成功的时候返回了conn对象,
    但是不成功哪?在发现异常,或者没有成功返回的情况下,你的返回代码没有写,编译器认为你的方法出口不完备。
    比如你写一个
    public boolean method(){
      if(XXX){
        return true;
      }
      else{
          
      }
    }
    也会出同样的错误。
      

  2.   

    因为你的这个方法是有返回值的,而你在捕获异常时,只是把错误信息打出来,并没有返回任何东西。
    解决办法:
      在异常处理中,最后都加个返回语句:return null;
      

  3.   

    public Connection getConnection() throws SQLException,ClassNotFoundException{
             Connection conn = null;
    try{
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        conn =  DriverManager.getConnection("jdbc:odbc:orac", "System", "manager");
       }catch(ClassNotFoundException e1){
           System.out.println("驱动程序装载错误");
           e1.printStackTrace();
       }catch(SQLException es){
         System.out.println("sql语句执行错误");
         es.printStackTrace();
       }
       return conn;
              }
      

  4.   

    public Connection getConnection() throws SQLException,ClassNotFoundException
    {
    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

                               return DriverManager.getConnection             ("jdbc:odbc:orac", "System", "manager");
    //return con;
    }
    catch(ClassNotFoundException e1)
    {
    System.out.println("驱动程序装载错误");
    e1.printStackTrace();
    }
    catch(SQLException es)
    {
    System.out.println("sql语句执行错误");
    es.printStackTrace();
    }
    return null;
              }
      

  5.   

    或者这样:
     Connection con = null;
     try{
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
       con = DriverManager.getConnection("jdbc:odbc:orac", "System", "manager");
     } catch(ClassNotFoundException e1){
        System.out.println("驱动程序装载错误");
        e1.printStackTrace();
     } catch(SQLException es){
        System.out.println("sql语句执行错误");
        es.printStackTrace();
     }
     return con;
      

  6.   

    accp(accp) ::你这就不能得到ResultSet了阿 :)