使用JDBC连接到在线数据库时遇到问题。
这是我迄今为止所做的一切清单:
http://www41.zippyshare.com/v/70987939/file.html
当我想连接到我的数据库时,我收到一个错误:
用户'user_name'@'xx.xx.xx.xxx'拒绝访问(使用密码:是) 。 其中xx.xx.xx.xxx是IP地址
以下是连接方法的代码:
public String connectWithDataBase(int type) throws SQLException {
String user = DB.login.getLoginData(type).getLogin();
String password = DB.login.getLoginData(type).getPassword();
String result = null;
connectionStatus = false;
if (connection == null || connection.isClosed()) {
try {
Class.forName(DB.baseConfig.DATA_BASE_DRIVER_NAME).newInstance();
connection = DriverManager.getConnection(
DB.baseConfig.DATA_BASE_ONLINE_URL, user, password);
operation = connection.createStatement();
result = "Connecting succesfull!";
connectionStatus = true;
}
catch (ClassNotFoundException e)
{
result = "Driver error.";
}
catch (SQLException e)
{
result = "Can't connect to database.";
System.out.println(e.getMessage());
e.printStackTrace();
}
catch (InstantiationException | IllegalAccessException ex)
{
result = "Conection error.";
}
}
return result;
}
具有配置:
的课程// Name
public final String DATA_BASE_ONLINE = "xxx_zzz";
// Config data
public final String ONLINE_DATA_BASE_PORT = "xxx.yyy.pl:3306";
public final String ONLINE_DATA_BASE_TYPE = "mysql";
public final String ONLINE_DATA_BASE_DRIVER_NAME = "com.mysql.jdbc.Driver";
public final String ONLINE_DATA_BASE_ENCODING = "?useUnicode=true&characterEncoding=utf8"; // B. WAŻNE!!!
// Online base URL:
public final String DATA_BASE_ONLINE_URL = "jdbc:" + ONLINE_DATA_BASE_TYPE + "://"
+ ONLINE_DATA_BASE_PORT + "/" + DATA_BASE_ONLINE + ONLINE_DATA_BASE_ENCODING;
使用登录数据:
进行课程// Base users types
public final int ONLINE = 0;
// User type --> loging data
private final HashMap<Integer, FlowLoginData> loginData = new HashMap<>();
// Nazwa tabeli
private final String TABLE_USERS = "users";
// Pola w tabeli
private final String TABLE_USERS_ID = "id";
private final String TABLE_USERS_PESEL = "pesel_number";
private final String TABLE_USERS_PRIV = "priv_level";
private final String TABLE_USERS_ONLINE = "is_online";
// Zmienna pomocznicza
private final String DASH = "'";
public DBLogin() {
loginData.put(this.ONLINE, new FlowLoginData("user", <-- "user" was added to base
"xxxxxxxxx"));
}
有人能告诉我哪里出错了吗?