我正在尝试在Ubuntu计算机上的eclipse中将mysql连接到Java,但是我遇到了问题。 我已经安装了mysql-connector-java-5.1.47
请在下面找到我的代码:
Package com.dataproviders;
import java.sql.DriverManager;
import com.mysql.jdbc.Connection;
public class DbData {
public static void main(String[] args) throws Throwable {
// TODO Auto-generated method stub
//Connection conn=null;
String dburl="jdbc//mysql://localhost:3306/nishadagar";
//String driver="com.mysql.jdbc.Driver";
//Class.forName("com.mysql.jdbc.Driver");
Connection conn=(Connection) DriverManager.getConnection(dburl, "root", "root");
System.out.println("success");
}
请在下面找到错误:
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc//mysql://localhost:3306/nishadagar
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at com.dataproviders.DbData.main(DbData.java:15)
答案 0 :(得分:0)
连接URL在语法上似乎不正确。 连接网址应为:
String dburl="jdbc:mysql://localhost:3306/nishadagar";
双斜杠已被冒号代替。请参阅官方文档here。