用Java连接MySQL数据库
有人能帮我解决这个错误吗?这是语法错误吗 用户名:root 没有密码 代码:用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 ''@
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
等等。我假设这里使用相同的规则。