gpt4 book ai didi

java - 此代码显示错误: "No suitable Driver found for jdbc:mysql://localhost:3306/ab"

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

import java.sql.SQLException;  
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String a=t1.getText();
{try {
String driver = "com.mysql.jdbc.Driver";
Class.forName(driver);
Connection C=DriverManager.getConnection("jdbc:mysql://localhost:3306/ab","root","root");
Statement S=C.createStatement();
String query="Insert into ab values('"+a+"');";
S.executeUpdate(query);
}
catch (Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
} }
}

我给出了正确的地址,但它显示未找到驱动程序。我正在使用 mysql-connector-C-6.1。它在我的构建路径中。我已经重新启动MySQL。我还使用 root 和密码从命令行登录,并且连接正常。我当前在“状态”中没有看到端口 3306。

最佳答案

您确定使用的是连接器-c吗?顾名思义,这个是针对 C 语言的,而不是针对 java 的。您应该使用连接器-j 库。

关于java - 此代码显示错误: "No suitable Driver found for jdbc:mysql://localhost:3306/ab",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43125636/

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