for the past few days i've been trying to solve an issue i'm having with my Android code where i execute two different threads, the first one that executes when i start the app works perfectly and there are no errors with the query. However the second thread that executes when I click the submit button is not executing the SQL query.
Here's the code:
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    submitButton = (Button) findViewById(R.id.submitButton);
    submitButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Toast.makeText(MainActivity.this,"This works",Toast.LENGTH_LONG).show();
            service = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            checkPermission();
            criteria = new Criteria();
            String provider = service.getBestProvider(criteria, false);
            if (provider != null & !provider.equals("")) {
                Location location = service.getLastKnownLocation(provider);
                service.requestLocationUpdates(provider, 2000, 1, MainActivity.this);
                if (location != null) {
                    onLocationChanged(location);
                } else {
                    Toast.makeText(MainActivity.this, "location not found", Toast.LENGTH_LONG).show();
                }
            } else {
                Toast.makeText(MainActivity.this, "Provider is null", Toast.LENGTH_LONG).show();
            }
            selectionEvent = eventSpinner.getSelectedItem().toString();
            insertThread.start();
        }
    });
    sqlThread.start();
}
Thread sqlThread = new Thread(){
    public void run(){
        alertHandler = new Handler(Looper.getMainLooper());
        try{
            Class.forName("org.postgresql.Driver");
            String url = "localhost:5432";
            Connection conn = DriverManager.getConnection(url,"arodriguez","alejandro2017");
            String statementSQL = "SELECT * FROM incidencias";
            Statement statement = conn.createStatement();
            ResultSet resultSet = statement.executeQuery(statementSQL);
            while(resultSet.next()){
                tiposIncidencias.add(resultSet.getString(2));
                naturalezaIncidencias.add(resultSet.getString(3));
            }
            alertHandler.post(new Runnable() {
                @Override
                public void run() {
                    addDefaultItemsOnTypeSpinner();
                    addDefaultItemsOnEventSpinner();
                }
            });
            String statementSQL2 = "INSERT INTO arodriguez.prueba (description,x,y) VALUES ('"+selectionEvent+"',"+latitude+","+longitude+")";
            Statement s = null;
            s = conn.createStatement();
            s.executeUpdate(statementSQL2);
            conn.close();
        } catch (SQLException se){
            Toast.makeText(MainActivity.this,se.toString(),Toast.LENGTH_LONG).show();
        } catch (ClassNotFoundException e){
            Toast.makeText(MainActivity.this,e.toString(),Toast.LENGTH_LONG).show();
        } catch (Exception ex){
            Log.d("Error",ex.toString());
        }
        return;
    }
};  
Thread insertThread = new Thread(){
    public void run(){
        alertHandler = new Handler(Looper.getMainLooper());
        try{
            alertHandler.post(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(MainActivity.this,selectionEvent,Toast.LENGTH_LONG).show();
                }
            });
            Class.forName("org.postgresql.Driver");
            String url = "jdbc:postgresql://localhost:5432/sde";
            Connection conn = DriverManager.getConnection(url,"arodriguez","alejandro2017");
            String statementSQL = "INSERT INTO arodriguez.prueba (description,x,y) VALUES ('"+selectionEvent+"',"+latitude+","+longitude+")";
            Statement statement = null;
            statement = conn.createStatement();
            statement.executeUpdate(statementSQL);
            conn.close();
        }catch (SQLException se){
            Log.d("Error",se.toString());
        } catch (ClassNotFoundException e){
            Log.d("Error",e.toString());
        } catch (Exception ex){
            Log.d("Error",ex.toString());
        }
        return;
    }
};
For some reason if I add the insert query in the first thread it does works:
     String statementSQL = "INSERT INTO arodriguez.prueba (description,x,y) VALUES ('"+selectionEvent+"',"+latitude+","+longitude+")";
     Statement statement = null;
     statement = conn.createStatement();
     statement.executeUpdate(statementSQL);
Am I doing something wrong?
