what exactly does this do Class.forName(“com.mysql.jdbc.Driver”).newInstance();

后端 未结 5 1813
孤独总比滥情好
孤独总比滥情好 2020-12-30 02:57

While connecting to MySQL database I do following steps

Connection con = null;
Resultset rs = null;
Statement st = null;
Class.forName(\"com.mysql.jdbc.Drive         


        
5条回答
  •  Happy的楠姐
    2020-12-30 03:46

    It will create a new instance of the com.mysql.jdbc.Driver class and hence call the static initialization which will register the driver with the DriverManager so you can create mysql connections based on the URL you use in the second line.

    The class however should be in the mysql.jar.

提交回复
热议问题