gpt4 book ai didi

java - 线程中的异常 "main"java.sql.SQLException : No suitable driver found for

转载 作者:行者123 更新时间:2023-11-29 23:19:00 25 4
gpt4 key购买 nike

我正在尝试连接到 MySQL 数据库,我在本地主机上使用 phpmyadmin 创建了 SQL 数据库。我的代码看起来是正确的,并且我已将 JAR 文件添加到 eclipse 中。我用谷歌搜索了该错误,并在这里发现了许多相同的主题,但无法解决该问题。这是我的代码:

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));
}
}
}

这是确切的错误:

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"

应该是:

"jdbc:mysql://localhost:3306/g52apr"

已编辑将 SQL Server 引用更改为 MySql

关于java - 线程中的异常 "main"java.sql.SQLException : No suitable driver found for,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27506184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com