Loading class com.mysql.jdbc.Driver ... is deprecated message
It isn't an error; it is a warning (or advisory) message resulting from a
Class.forName("com.mysql.jdbc.Driver")
call. Your code continues to run despite the message.
It is mainly telling you that the name of the driver class has changed to com.mysql.cj.jdbc.Driver
. So, instead use:
Class.forName("com.mysql.cj.jdbc.Driver")
It is also letting you know that since Java 6 (JDBC 4.0) it is usually not necessary to manually load the driver class using Class.forName
anyway, because JDBC is now able to load the correct driver itself (provided that the driver .jar is available on the class path).
java netbeans The new driver class is `com.mysql.cj.jdbc.Driver'
I tried changing my url of database from convertToNull
to CONVERT_TO_NULL
but the same error occurs.
Here is my connection code & im just displaying the contents of database in my form with the help of jTable in Netbeans
public class MysqlConnection {
public Connection con;
/*public ResultSet rs;
public Statement st;
public PreparedStatement ps;
public DataSource ds=null;*/
public String User;
public String Uid;
public String Pwd;
public String StrUrl="jdbc:mysql://localhost:50781/jayshreesteels?zeroDateTimeBehavior=CONVERT_TO_NULL";
public String StrUid="root";
public String StrPwd= "root";
public static String StrUser;
public static void main(String[] args) throws ClassNotFoundException, SQLException{
String Url="jdbc:mysql://localhost:50781/jayshreesteels?zeroDateTimeBehavior=CONVERT_TO_NULL";
Class.forName("com.mysql.cj.jdbc.Driver");
}
public MysqlConnection() throws SQLException {
this.con = DriverManager.getConnection(StrUrl, "root", "root");
}
}
Failed to load driver class com.mysql.jdbc.Driver
The answer is so embarrassing. I appended the driver line of application.properties with a semicolon ...
Obviously, it did't recognize that driver.
Confusion in SPI automatic registration of com.mysql.cj.jdbc.Driver
The MySQL Connector/J developer guide is still referring to the Class.forName. See https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-usagenotes-connect-drivermanager.html
But starting with JDBC 4, the Service Provider Interface is used, so the call should no longer be required. (And for me it works without the Class.forName call!)
Details about the SPI:
- https://www.baeldung.com/java-spi
- https://docs.oracle.com/javase/8/docs/api/java/sql/DriverManager.html
Related Topics
How to Convert a String to Another Locale
Inserting Text into an Existing File via Java
How to Call Subclasses' Methods on a Superclass Object
Printing Debug Info on Errors with Java 8 Lambda Expressions
Java Division by Zero Doesnt Throw an Arithmeticexception - Why
Why Equal Operator Works for Integer Value Until 128 Number
How to Ensure Hashcode() Is Consistent with Equals()
Comparing Float/Double Values Using == Operator
Where Is the Javabean Property Naming Convention Defined
Text-Mouseover Popups Over a Swing Jtextarea
Where Should I Put the Log4J.Properties File
How to Use Jsch for Ssh Key-Based Communication
How to Force Browser to Download File
Jschexception: Algorithm Negotiation Fail