Reputation: 261
I'm trying to connect to mysql database using JdbcConnectionSource in an android application that should use ormlite. I have this method that should connect to the database and create a user table if it doesn't exist:
public UserDao() throws SQLException {
connectionSource = new JdbcConnectionSource("jdbc:mysql://localhost:3306/sell_buy", "root", "");
utilisateurDao = DaoManager.createDao(connectionSource, User.class);
TableUtils.createTableIfNotExists(connectionSource,
Utilisateur.class);
}
the problem is that i get a com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure whenever the methood is executed !. I'm pretty sure that the database is running and the information(username and password to connect to the database ) are ok !
I hope someone will help me and thx in advance.
Upvotes: 0
Views: 1472
Reputation: 261
First i should perform network work in an AsyncTask or a new Thread second to refer the localhost i should use the address 10.0.2.2 since i'm working with the android emulator.
Resolved !
Upvotes: 1