I have a remote Windows Server in which I have a database in a SQL Workbench. On the other hand, I have an Android application that needs to connect to the database of the remote Windows Server, but the problem is that it doesn't connect, and it doesn't give me any error.
I checked that the port 3306 of the remote server is opened. What else should I try?
This is my code:
AsyncTask<String, Void, String> a = new AsyncTask<String, Void, String>() {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(String s) {
Log.i("postExecute",s);
super.onPostExecute(s);
}
@Override
protected String doInBackground(String... params) {
String response= "blank";
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String bdAddress = "jdbc:mysql://XXX.XXX.XXX.XXX:3306/dataBaseName";
String bdUsername = "XXXXX";
String bdPassword = "XXXXX";
conn = DriverManager.getConnection(bdAddress, bdUsername, bdPassword);
//THE CODE DOESN'T REACH THIS POINT AND IT DOESN'T GIVE ANY ERROR
Statement stmt = null;
try {
conn.setAutoCommit(false);
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM tableName");
while (rs.next()) {
response= rs.getString("tableColumn");
}
conn.commit();
} catch (SQLException ex) {
ex.printStackTrace();
conn.rollback();
} finally {
if (stmt != null) {
stmt.close();
}
conn.setAutoCommit(true);
}
} catch (SQLException sqlException) {
sqlException.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return response;
}
};
a.execute(null, null, null);
Thank you so much!