[英]No suitable driver found, SQLException in Java
I have not worked with databases before and wanted to practice with video tutorials, but I immediately get an error.我以前没有使用过数据库,想通过视频教程进行练习,但我立即遇到错误。
this is my code: (with database i work in.netbeans)这是我的代码:(我使用的数据库是.netbeans)
` `
package javaapplicationdatabase;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;
public class JavaApplicationDataBase {
public static final String DRIVER_NAME = "com.mysql.cj.jdbc.Driver";
public static final String CONN_STRING = "jdbs:mysql://localhost:3306/?user=root&password=root";
public static void main(String[] args) {
Enumeration<Driver> drivers = DriverManager.getDrivers();
while(drivers.hasMoreElements())
System.out.println(drivers.nextElement());
try {
Class.forName(DRIVER_NAME);
} catch (ClassNotFoundException ex) {
System.out.println("MySQL driver not found!");
return;
}
try {
Connection conn = DriverManager.getConnection(CONN_STRING);
} catch (SQLException ex) {
System.out.println("Cannot open connection!" + ex.getMessage());
return;
}
}
}
` `
in libraries of this project i connected mysql-connected.在这个项目的库中,我连接了 mysql-connected。 connect mysql connected in.netbeans project连接 mysql 连接 in.netbeans 项目
I tried to reinstall mysql and write the path to the driver in a different way, but it still gives this error.我试过重装mysql,用不同的方式写入驱动的路径,还是报这个错。 I read answers to other questions about this error and they all say that you need to connect the jar file, but i have it connected and i don't know how else to solve the problem.我阅读了有关此错误的其他问题的答案,他们都说您需要连接 jar 文件,但我已经连接了它,但我不知道如何解决该问题。
In my opinion it is can be typo in your url, try change:我认为这可能是您的 url 中的错字,请尝试更改:
jdbs:mysql:
to到
jdbc:mysql:
just add the MySQL JDBC JAR into class path if you are running on Java SE6 and driver is JBC 4.0 compliant, eg mysql-connector-java-5.1.36-bin.jar.只需将 MySQL JDBC JAR 添加到 class 路径,如果您在 Java SE6 上运行并且驱动程序符合 JBC 4.0,例如 mysql-connector-java-5.1.36-bin.8820128889
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.