title: How to connect Android Studio to Network and then to MS SQL?
body: <p>lately i've been trying to develop a app in Android Studio that it should print results in my emulador, but since i'm a beginner in this field(Java/Android) i searched a lot and i discover that the difference between my code and the others code has been that i'm trying to connect directly from my Android App to SQL, and what i really want it's to connect from Android to Network(of my company) and then connect to SQL Server, can someone help me? </p>
  
  <p>Here it is the code i develop: (Android App directly to SQL Server)</p>
  
  <p>public class manutencao extends Activity {</p>
  
  <pre><code>Button executar;
  EditText buscar;
  ListView listar;
  Connection connect;
  SimpleAdapter dataAdapt;
  
  
  
  private void declarar()
  {
      executar = (Button) findViewById(R.id.btn_Executar);
      buscar = (EditText) findViewById(R.id.et_campo);
      listar = (ListView) findViewById(R.id.listView);
  
  }
  
  private void inicializar()
  {
      declarar();
      buscar.setText("SELECT TOP 10 * FROM Gav_Auto_Manutencao_Autonoma");
      connect = CONN("*user","*pass", "GAV_Manutencao", "*ip");
  
  }
  
  @SuppressLint("NewApi")
  private Connection CONN(String _user, String _passe, String _BD, String _server)
  {
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
      StrictMode.setThreadPolicy(policy);
      Connection conn = null;
      String connURL = null;
      try {
  
          Class.forName("net.sourceforge.jtds.jdbc.Driver");
          connURL = "jdbc:jtds:sqlserver://" + _server + ";" + "databaseName=" + _BD + ";user=" + _user + ";password=" + _passe + ";";
          conn = DriverManager.getConnection(connURL);
  
      } catch (SQLException se) {
  
          Log.e("Erro", se.getMessage());
  
      }  catch (ClassNotFoundException e) {
          Log.e("Erro", e.getMessage());
  
      } catch (Exception e) {
          Log.e("Erro", e.getMessage());
      }
  
      return conn;
  }
  
  
  public void QuerySQL(String comandoSQL){
      ResultSet rs;
      try {
  
          Statement statement = connect.createStatement();
          rs = statement.executeQuery(comandoSQL);
  
          List&lt;Map&lt;String, String&gt;&gt; data = null;
          data = new ArrayList&lt;Map&lt;String, String&gt;&gt;();
  
          while(rs.next()){
              Map&lt;String, String&gt; datanum = new HashMap&lt;String, String&gt;();
              datanum.put("A", rs.getString("Posto"));
              data.add(datanum);
          }
  
          String[] from = {"A"};
          int [] views = {R.id.txt_titulo, R.id.txt_conteudo};
          dataAdapt = new SimpleAdapter(this, data, R.layout.modelo, from, views);
          listar.setAdapter(dataAdapt);
      } catch (Exception e) {
          Log.e("ERRO", e.getMessage());
      }
  }
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_manutencao);
  
      inicializar();
  
      executar.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              QuerySQL(buscar.getText().toString());
  
  
          }
      });
  
  }
  </code></pre>