为啥java链接数据库是包这种错No suitable driver found for jdbc://mysql://localhost:3306/user?
packagehello;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.SQ...
package hello;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Test {
public static void main(String[] args) throws SQLException {
// TODO Auto-generated method stub
String url="jdbc://mysql://localhost:3306/user";
String user="root";
String password="123456";
Connection conn=null;
try {
Class.forName("com.mysql.jdbc.Driver");
DriverManager.getConnection(url, user, password);
System.out.println("链接数据库成功");
} catch (ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
conn.close();
}
}
} 展开
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Test {
public static void main(String[] args) throws SQLException {
// TODO Auto-generated method stub
String url="jdbc://mysql://localhost:3306/user";
String user="root";
String password="123456";
Connection conn=null;
try {
Class.forName("com.mysql.jdbc.Driver");
DriverManager.getConnection(url, user, password);
System.out.println("链接数据库成功");
} catch (ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
conn.close();
}
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询