No suitable driver found for jdbc:mysql:localhost:mysql when using JDBC to connect to MySQL database
MySQL version: 8.0.26
Change the driver to:
“jdbc:mysql://localhost:3306/mysql?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai”
import java.sql.*;
public class JDBCTest {
public static void main(String[] args) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai","root","dcc12345");
System.out.println("数据库连接成功");
} catch (SQLException throwables) {
throwables.printStackTrace();
}finally {
if(conn != null){
try {
conn.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}
}
}
The writing method of the new version of MySQL driver is different from that of the previous version. Jar package 8.0. * everything is common
Read More:
- Reason: failed to determine a suitable driver class [Solved]
- [Solved] Spring jdbctemplate Error: ‘Java. SQL. Driver’ for property ‘driver’: no
- How to Solve JasperFillManager.fillReport Stuck issue (No Error and No Processing)
- How to Solve Junit Unit Test Error: “No runnable methods“
- ERROR launching ‘JD-GUI‘ No suitable Java version [How to Solve]
- How to Solve Error: Invalid bound statement (not found)
- How to Solve Mybatis error: invalid bound statement (not found)
- How to Solve zuul Forwarding error (No Retrayable)
- How to Solve JDBC connection error in spring MVC integration
- How to Solve c3p0 error (Cause & Solution)
- How to Solve JUnit Debugging initializationerror ERROR
- How to Solve JVM Common Errors: outofmemoryerror & stackoverflowerror
- How to Solve IBM MQ Connect Error Code 2035
- [Solved] Cannot find class: com.mysql.jdbc.Driver
- [How to Fix]No executorfactory found to execute the application
- How to Solve Nosuchmethoderror Error
- How to Solve shiro Set sessionIdUrlRewritingEnabled Error (jessionid Removed)
- How to Solve RAR Files Extract Error with sevenzipjbinding (Multithread Processing)
- How to Solve SQL comments error in the mybatis query
- How to Solve Flick operate Error: not serialized