你这些代码必须写在try中,然后下面要catch各种exception才行!不然编译肯定过不去!
建议你先看看java的异常处理

解决方案 »

  1.   

    是的,Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");这个代码有可能产生Exception,所以需要将其放在
    try{
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }catch(sqlexception e){
    //e.getMessage();
    }中
    或者在你的方法中throws sqlexception即可,example:
    public void get()throws sqlexception{
    }
      

  2.   

    try {
    // Code that could generate an exception goes here.
    // If an exception is generated, the catch block below
    // will print out information about it.
    } catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    }try {
    Class.forName("myDriverClassName");
    } catch(java.lang.ClassNotFoundException e) {
    System.err.print("ClassNotFoundException: "); 
    System.err.println(e.getMessage());
    }
      

  3.   

    一般写一段代码最好给它弄个Try{}
    这样,比较好处理,而且,也显得你的代码很有条理。^@^
      

  4.   

    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String url="jdbc:odbc:kelon";
    Connection sqlcon=java.sql.DriverManager.getConnection(url,"sa","1688");
    }catch(Exception e){
      e.printstatck();
    }