1

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!

jartymcfly
  • 1,753
  • 6
  • 27
  • 47
  • Please read: http://stackoverflow.com/questions/15853367/jdbc-vs-web-service-for-android – Morrison Chang May 27 '16 at 17:13
  • If you're exposing your MySQL port to the world you're asking for trouble. At the very least use a VPN or SSH tunnel. – tadman May 27 '16 at 17:21
  • Is your MySQL DB configured for remote access. Did you bind your IP and not Localhost to 3306 and GRANT your user access for remote connections? – apesa May 27 '16 at 17:42

0 Answers0