Class.forName(“com.mysql.jdbc.Driver”).newInstance()

前端 未结 4 848
盖世英雄少女心
盖世英雄少女心 2020-12-18 14:14

I am having this error on Netbeans 7.2, it says that ClassNotFoundexception and InstantationException. I am really stuck on this matter. Kindly help me.

prot         


        
4条回答
  •  囚心锁ツ
    2020-12-18 15:07

    All you need is Class.forName("com.mysql.jdbc.Driver")

    This acts like class loader and load your driver class for you. For that you need to add the corresponding jar file(which has the driver implementation). So download and add mysql-connector.jar in your class path.

    Note : If you are using Java 7 then there is no need to even add the Class.forName("com.mysql.jdbc.Driver") statement.Automatic Resource Management (ARM) is added in JDBC 4.1 which comes by default in Java 7.

提交回复
热议问题