连接到JDBC MySQL数据库 [英] Connection to a JDBC MySQL databse
本文介绍了连接到JDBC MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用Java连接到JDBC MySQL数据库,但是当我尝试运行我的程序时,我收到以下错误:
I am trying to connect to a JDBC MySQL database using Java, but I am getting the following error when I try to run my program:-
找不到适合的
的驱动程序a9442ca6-992c-411b-8bda-a42f00a0ab2e.mysql.sequelizer.com
No suitable driver found for a9442ca6-992c-411b-8bda-a42f00a0ab2e.mysql.sequelizer.com
我下载了以下Jar文件并将其添加到我的项目中:
I downloaded the following Jar file and added it to my project:
mysql-connector-java5.1.34-bin.jar
我不知道是否需要在声明中添加一些import任何帮助将非常感激。
I'm not sure if I need to add some kind of 'import' statement in my declaration maybes? Any help would be much appreciated.
我的代码如下: -
My code is as follows:-
package dvddblibrary;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import java.util.Scanner;
public class DBConnect {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
try
{
String host = "xxx";
String uName = "xxx";
String uPass = "xxx";
Connection con = DriverManager.getConnection(host, uName, uPass);
}
catch (SQLException err)
{
System.out.println(err.getMessage());
}
}
}
推荐答案
试试这个:
package dvddblibrary;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBConnect {
public static void main(String[] args) {
try {
String host = "xxx";
String uName = "xxx";
String uPass = "xxx";
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(host, uName, uPass);
} catch (SQLException err) {
System.out.println(err.getMessage());
}
}
}
这篇关于连接到JDBC MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文