【发布时间】:2015-04-22 21:16:50
【问题描述】:
我正在尝试连接到名为 OTA 的数据库上的 Openshift MYSQL 数据库
每当我尝试连接时,我都会收到错误 -
java.sql.SQLException: 用户 'admin881Rhs7'@'localhost' 的访问被拒绝(使用密码:否)
当我使用密码时
private String ConnectionString = "jdbc:mysql://localhost:3306/OTA?"
+ "user=admin881Rhs7&password=9JDlLn1r****";
public ResultSet ExecuteSQL(String query) throws Exception {
try {
Class.forName("com.mysql.jdbc.Driver");
// setup the connection with the DB.
connect = DriverManager.getConnection(ConnectionString);
// statements allow to issue SQL queries to the database
statement = connect.createStatement();
// resultSet gets the result of the SQL query
resultSet = statement.executeQuery(query);
// writeResultSet(resultSet);
我似乎无法使用此连接连接到远程数据库,但我可以使用 PHPMyAdmin 登录到数据库
注意:我尝试将连接字符串中的“localhost”更改为数据库上服务器的 IP,但也不起作用
我还授予我的用户特权,但仍然说(使用密码:NO)
感谢任何帮助,请注意这是在开放式服务器上。
【问题讨论】:
-
试试
String ConnectionString = "jdbc:mysql://localhost:3306/OTA"和DriverManager.getConnection(ConnectionString, "yourUsername", "yourPassword")。 -
不,还是同样的错误 java.sql.SQLException: Access denied for user 'admin881Rhs7'@'localhost' (using password: NO)
-
好吧,那就试着为
using password: NO找个理由吧。您的登录似乎由于某种原因省略了密码。 -
是的,我也想知道为什么会这样:'(