Reputation: 545
I want to access to a remote database(Mysql) ,but always an error occure : what it can be the error?
try{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://@IP:3306/jira313";
String user = "jirauser";
String passwd = "jirauser";
Connection conn = DriverManager.getConnection(url, user, passwd);
}catch (Exception e) {
e.printStackTrace();
}
The error is:
java.sql.SQLException: Access denied for user 'jirauser'@'MyIP' (using password: NO)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:910)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3923)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1273)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2031)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at javaapplication1.connexion.main(connexion.java:29)
Upvotes: 0
Views: 992
Reputation: 12538
The answer to your question is in your exception:
java.sql.SQLException: Access denied for user 'jirauser'@'MyIP' (using password: NO)
Log onto the database, if you have access and try:
GRANT ALL ON YOUR_DATABASE.* TO jirauser@'YOUR_IP' IDENTIFIED BY 'YOUR_PASSWORD';
Upvotes: 2
Reputation: 1736
Setup mysql to allow remote connection for the user.
grant <permission> on <database> to <user>@<location> identified by <password>
Upvotes: 0
Reputation: 8744
You don't have the rights to access the remote mysql server.
Go on the server, log in to MySql and run GRANT ALL PRIVILEGES ON *.* TO 'jirauser'@'%'
(this will give you full access -> you should read about privileges first and add the just the privileges you need adding users to MySql
Upvotes: 0
Reputation: 14593
Your user might be local, first try with mysql client. If it also gives error modify user rights to be able to connect from remote.
Upvotes: 1