[英]Found this error "No suitable driver found for jdbc:mysql//localhost:3306/student"
I was try to create simple java student GUI
app in IntelliJ IDEA
and its working fine.我试图在
IntelliJ IDEA
中创建简单的 java 学生GUI
应用程序,并且工作正常。 Then I just try to connect database to inset all data into MYSQL, so I create Schema( student
) and Table( appointment
) in MySQL Workbatch
and then connect that database in IntelliJ IDEA Database
window you can see in the picture and its successfully configured it.然后我只是尝试连接数据库以将所有数据插入 MYSQL,所以我在
MySQL Workbatch
中创建模式( student
)和表( appointment
),然后在IntelliJ IDEA Database
Z05B8C74CBD96FBF2DE4C1A3527 中连接该数据库,您可以在图片中看到它成功配置的 FBF2DE4C1A3527 .
Now I try to create connection via below line.现在我尝试通过下面的行创建连接。
Connection con = DriverManager.getConnection("jdbc:mysql//localhost:3306/student","root","root");
Connection con = DriverManager.getConnection("jdbc:mysql//localhost:3306/student","root","root");
But this line give me this error Error: No suitable driver found for jdbc:mysql//localhost:3306/student
但是这一行给了我这个错误
Error: No suitable driver found for jdbc:mysql//localhost:3306/student
So I google it and I found this line.所以我谷歌它,我找到了这条线。
Class.forName("com.mysql.cj.jdbc.Driver");
Class.forName("com.mysql.cj.jdbc.Driver");
but this line give this error Error: com.mysql.cj.jdbc.Driver
但是这条线给出了这个错误
Error: com.mysql.cj.jdbc.Driver
Please everyone have a look in it, Its very helpful to me and other one who face this issue.请大家看看它,它对我和其他面临这个问题的人非常有帮助。
private DBconnectionSingleton() throws SQLException {
// create single instance of DB connection
Properties connectionProps = new Properties();
connectionProps.put("user", login);
connectionProps.put("password", password);// port & db name
System.out.println("Loading driver...");
try {
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("Driver loaded!");
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Cannot find the driver in the classpath!", e);
}
conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/student",
connectionProps
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.