Java 获取与MySQL连接器的连接时出错

Java 获取与MySQL连接器的连接时出错,java,mysql,Java,Mysql,错误: No suitable driver found for jdbc:mysql://localhost:3306 at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) 这是我的密码 public Connection getConnection() throws SQLException { Conne

错误:

No suitable driver found for jdbc:mysql://localhost:3306
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
这是我的密码

public Connection getConnection() throws SQLException {
        Connection conn;
        Properties connectionProps = new Properties();
        connectionProps.put("user", "root");
        connectionProps.put("password", "pass");
        conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/" , connectionProps);
        System.out.println("Connected to database");
        return conn;

    }

你进口了吗<代码>导入java.sql.*试着把它放在最前面。
也把这个
Class.forName(“com.mysql.jdbc.Driver”)DriverManager.getconnection
之前输入code>以识别驱动程序。

在获得连接之前,您需要注册驱动程序(如果已经注册,则不会执行任何操作):


哦,谢谢你,先生。我添加了Class.forName(“com.mysql.jdbc.Driver”);在getConnection方法之前,它是有效的。再次感谢。文档中关于驱动程序的说明是什么?你试过什么?
public Connection getConnection() throws SQLException {
        String myDriver = "com.mysql.jdbc.Driver";
        String myUrl = "jdbc:mysql://localhost:3306/";
        Class.forName(myDriver);
        Connection conn;
        Properties connectionProps = new Properties();
        connectionProps.put("user", "root");
        connectionProps.put("password", "pass");
        conn = DriverManager.getConnection(myUrl , connectionProps);
        System.out.println("Connected to database");
        return conn;
}