[英]Exception in thread “main” java.sql.SQLException: No suitable driver found for
I'm trying to connect to a MySQL database, I created the SQL database with phpmyadmin on localhost. 我试图连接到MySQL数据库,我在localhost上用phpmyadmin创建了SQL数据库。 My code seems correct and I have the JAR file added to eclipse.
我的代码似乎正确,并且我已将JAR文件添加到eclipse中。 I have googled the error and found on here many topics that are the same but haven't been able to resolve the problem.
我已经搜索了该错误,并在此处找到了许多相同但无法解决问题的主题。 Here is my code:
这是我的代码:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
public class dbconnection {
public static void main (String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:msql://localhost:3306/g52apr","root", "");
java.sql.PreparedStatement statement = con.prepareStatement("select * from std_details");
ResultSet result = statement.executeQuery();
while (result.next()){
System.out.println(result.getString(1) + " " + result.getString(2));
}
}
}
This is the exact error: 这是确切的错误:
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:3306/g52apr
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at dbconnection.main(dbconnection.java:10)
"jdbc:msql://localhost:3306/g52apr"
should be: 应该:
"jdbc:mysql://localhost:3306/g52apr"
Edited Changed SQL Server reference to MySql 编辑对MySql的更改的SQL Server参考
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.