I'm trying to connect to my MYSQL database on db4free directly, security/reliability is of no concern here, it should just work good enough for a minimum viable product that will be later totally reconstructed from scratch, that's why I'm trying to connect this way. This is just some kind of concept application.
For one of the requirements, we need a server database.
I'm using ORMLite-core paired with ORMLite-jdbc, and trying the following code in Android Studio:
public class DatabaseHelper {
private ConnectionSource connectionSource;
private Dao<User, Integer> userDao;
private Dao<Settings, Integer> settingsDao;
private Dao<Prize, Integer> itemDao;
private Dao<CulturalCenter, Integer> localDao;
private Dao<Event, Integer> eventDao;
private static final DatabaseHelper dbHelper = new DatabaseHelper();
public static DatabaseHelper getInstance() {
return dbHelper;
}
private DatabaseHelper() {
try {
this.connectionSource = new JdbcConnectionSource("jdbc:mysql://85.10.205.173/mydb", "myacc", "mypass");
Log.d("Connection", "Do we reach here?" + connectionSource.getDatabaseType().getDatabaseName());
/**
* DAOS
*/
this.userDao = DaoManager.createDao(connectionSource, User.class);
TableUtils.createTable(connectionSource, User.class);
} catch (SQLException e) {
e.printStackTrace();
}
}
public Dao<User, Integer> getUserDao() {
return userDao;
}
This crashes on the TableUtils with the following error:
D/Connection: Do we reach here?MySQL W/art: Suspending all threads took: 8.202ms I/art: Background partial concurrent mark-sweep GC freed 5335(349KB) AllocSpace objects, 4(110KB) LOS objects, 40% free, 3MB/5MB, paused 9.637ms total 33.576ms I/TableUtils: creating table 'user' W/System.err: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure W/System.err: The last packet sent to the server was 0 ms ago.
I'm unable to connect like this, but I can connect just fine in my MySQL workbench on my windows pc with the credentials I provided in my code. I've googled a lot but I'm still very inexperienced working with databases on Android, and couldn't find any viable solution so far, I'd appreciate any help!
Thank you!