jdbc:
簡單示例
方法四:直接連class都不用寫,這樣得出的東西是什么很好奇就是只是不獲取driver?
看原始碼后發現:
package java.sql.DriverManager;
Applications no longer need to explicitly load JDBC drivers using
Class.forName(). Existing programs which currently load JDBC drivers usingClass.forName()will continue to work withoutmodification.
所以最簡單的方式為:
(p.getProperty(“user”)直接用user也行)
Connection conn = DriverManager.getConnection(url,p.getProperty(“user”),p.getProperty(“password”));
(當然可以的話還是加上Driver driver = Class.forName(com.mysql.cj.jdbc.Driver)畢竟免得有其他bug,因為他是從其他地方加載的,)
When the method
getConnectionis called, theDriverManagerwill attempt to locate a suitable driver from amongst those loaded at initialization and those loaded explicitly using the same classloader as the current applet or application.
后續待補充:
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/260128.html
標籤:其他
