Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用Java连接MySQL数据库_Java_Mysql - Fatal编程技术网

用Java连接MySQL数据库

用Java连接MySQL数据库,java,mysql,Java,Mysql,有人能帮我解决这个错误吗?这是语法错误吗 用户名:root 没有密码 代码: Class.forName("com.mysql.jdbc.Driver"); Connection conn = null; conn = DriverManager.getConnection("jdbc:mysql://localhost/main" + "user=root&password="); Access denied for user ''@

有人能帮我解决这个错误吗?这是语法错误吗

用户名:root 没有密码

代码:

    Class.forName("com.mysql.jdbc.Driver");

    Connection conn = null;
    conn = DriverManager.getConnection("jdbc:mysql://localhost/main"
            + "user=root&password=");
Access denied for user ''@'localhost' to database 'mainuser=root&password='
输出:

    Class.forName("com.mysql.jdbc.Driver");

    Connection conn = null;
    conn = DriverManager.getConnection("jdbc:mysql://localhost/main"
            + "user=root&password=");
Access denied for user ''@'localhost' to database 'mainuser=root&password='

您在
用户
之前错过了

DriverManager.getConnection("jdbc:mysql://localhost/main?" +
                               "user=root&password=");
它值得一读


您也可以尝试使用
属性
。看看构造器,任何一个都有更多的尝试

Properties connectionProps = new Properties();
connectionProps.put("user", "root");
connectionProps.put("password", "");

String url ="jdbc:mysql://localhost/main";

Connection conn = DriverManager.getConnection(url, connectionProps);

您在
用户
之前错过了

DriverManager.getConnection("jdbc:mysql://localhost/main?" +
                               "user=root&password=");
它值得一读


您也可以尝试使用
属性
。看看构造器,任何一个都有更多的尝试

Properties connectionProps = new Properties();
connectionProps.put("user", "root");
connectionProps.put("password", "");

String url ="jdbc:mysql://localhost/main";

Connection conn = DriverManager.getConnection(url, connectionProps);

您在
用户
之前错过了

DriverManager.getConnection("jdbc:mysql://localhost/main?" +
                               "user=root&password=");
它值得一读


您也可以尝试使用
属性
。看看构造器,任何一个都有更多的尝试

Properties connectionProps = new Properties();
connectionProps.put("user", "root");
connectionProps.put("password", "");

String url ="jdbc:mysql://localhost/main";

Connection conn = DriverManager.getConnection(url, connectionProps);

您在
用户
之前错过了

DriverManager.getConnection("jdbc:mysql://localhost/main?" +
                               "user=root&password=");
它值得一读


您也可以尝试使用
属性
。看看构造器,任何一个都有更多的尝试

Properties connectionProps = new Properties();
connectionProps.put("user", "root");
connectionProps.put("password", "");

String url ="jdbc:mysql://localhost/main";

Connection conn = DriverManager.getConnection(url, connectionProps);

您可以改为使用以下方法签名

public static Connection getConnection(String url, String user, String password) throws SQLException
在你的情况下是这样的

conn = DriverManager.getConnection("jdbc:mysql://localhost/main", "root", "");

您可以改为使用以下方法签名

public static Connection getConnection(String url, String user, String password) throws SQLException
在你的情况下是这样的

conn = DriverManager.getConnection("jdbc:mysql://localhost/main", "root", "");

您可以改为使用以下方法签名

public static Connection getConnection(String url, String user, String password) throws SQLException
在你的情况下是这样的

conn = DriverManager.getConnection("jdbc:mysql://localhost/main", "root", "");

您可以改为使用以下方法签名

public static Connection getConnection(String url, String user, String password) throws SQLException
在你的情况下是这样的

conn = DriverManager.getConnection("jdbc:mysql://localhost/main", "root", "");
你做错了 试试这个

(Jdbc:mysql://localhost/main,根,passwd)

你做错了 试试这个

(Jdbc:mysql://localhost/main,根,passwd)

你做错了 试试这个

(Jdbc:mysql://localhost/main,根,passwd)

你做错了 试试这个

(Jdbc:mysql://localhost/main,根,passwd)



您可以使用
mysql
工具从命令行进行连接吗?请尝试
conn=DriverManager.getConnection(“jdbc:mysql://localhost/main“,”根“,”)@user432,非常有效,谢谢!在
main
之后和
user=
之前不应该有
吗?如果您正在创建指向资源的URL,并且希望使用GET传递一些参数,则需要使用
protocol://address/to/resource?param1=value1¶m2=value2
等等。我假设这里使用相同的规则。您可以使用
mysql
工具从命令行进行连接吗?请尝试
conn=DriverManager.getConnection(“jdbc:mysql://localhost/main“,”根“,”)@user432,非常有效,谢谢!在
main
之后和
user=
之前不应该有
吗?如果您正在创建指向资源的URL,并且希望使用GET传递一些参数,则需要使用
protocol://address/to/resource?param1=value1¶m2=value2
等等。我假设这里使用相同的规则。您可以使用
mysql
工具从命令行进行连接吗?请尝试
conn=DriverManager.getConnection(“jdbc:mysql://localhost/main“,”根“,”)@user432,非常有效,谢谢!在
main
之后和
user=
之前不应该有
吗?如果您正在创建指向资源的URL,并且希望使用GET传递一些参数,则需要使用
protocol://address/to/resource?param1=value1¶m2=value2
等等。我假设这里使用相同的规则。您可以使用
mysql
工具从命令行进行连接吗?请尝试
conn=DriverManager.getConnection(“jdbc:mysql://localhost/main“,”根“,”)@user432,非常有效,谢谢!在
main
之后和
user=
之前不应该有
吗?如果您正在创建指向资源的URL,并且希望使用GET传递一些参数,则需要使用
protocol://address/to/resource?param1=value1¶m2=value2
等等。我假设这里使用相同的规则。