try{//要加上
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch....

解决方案 »

  1.   

    这个错误说明你的这行代码会报异常ClassNotFoundException 和SQLException 。原因也很好理解:装载驱动程序时可能找不到就出现前者异常;后者连接数据时出错则会报SQL异常。解决方法分别捕获,并给出客户提示。
    try
    {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con=DriverManager.getConnection("jdbc:odbc:Driver=
            {Microsoft AccessDriver (*.mdb)};DBQ=d:\\db1.mdb");
    }
    catch (ClassNotFoundException e)
    {
        System.out.println("没有找到驱动程序!");
    }
    catch (SQLException e)
    {
        System.out.prinln("连接数据库出错:" + e.toString());
    }