我正在尝试使用 jdbc 连接连接到远程 mysql 数据库。但我得到了
java.sql.SQLException:运行 java 类时,用户拒绝访问此异常。但是我可以使用 mysql 查询浏览器或 mysql 命令连接到这个数据库。我用以前的版本替换了 jdbc 驱动程序,但我仍然收到此错误。我只有对远程数据库的只读访问权限。请帮我解决这个问题。
try { // This will load the MySQL driver, each DB has its own driver Class.forName("com.mysql.jdbc.Driver"); // Setup the connection with the DB
connect = DriverManager .getConnection("jdbc:mysql://myremotehost/remotedatabase?user=username&password=password"); // Statements allow to issue SQL queries to the database statement = connect.createStatement(); // Result set get the result of the SQL query resultSet = statement .executeQuery("select * from mytable limit 10"); writeResultSet(resultSet); } catch (Exception e) { throw e; } finally { close(); }
谢谢
最佳答案
您好,我找到了解决此问题的方法。出现此错误是因为密码包含 & 符号。我们在 jdbc 连接字符串中使用 & 符号作为分隔符。
关于mysql - 获取 java.sql.SQLException : Access denied for user exception when connecting to remote mysql database,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13933869/