SQL Server Integration with Android [closed]

0

I'm having trouble connecting to Sql Server and Android. When I try to communicate, the message "No address associated with hostname." I already did everything I needed, I downloaded Drive jtds, I downloaded sql server 2017, and I could not make the communication, if someone can give me a help, I'll thank.

Full error message: Unknown server host name 'Unable to resolve host' 192.168.1.3projectandroid ": No address associated with hostname '.

      ip = "192.168.1.3";
    db = "projetoandroid";
    un = "sa";
    pass = "123";

    login.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            CheckLogin checkLogin = new CheckLogin();
            checkLogin.execute("");
        }
    });

}

public class CheckLogin extends AsyncTask<String,String,String>
{
    String z = "";
    Boolean isSuccess = false;

    @Override
    protected void onPreExecute()
    {
        //progressBar.setVisibility(View.VISIBLE);
    }

    @Override
    protected void onPostExecute(String r)
    {
       // progressBar.setVisibility(View.GONE);
        Toast.makeText(ParaTeste.this, r, Toast.LENGTH_SHORT).show();
        if(isSuccess)
        {
            Toast.makeText(ParaTeste.this , "Login Successfull" , Toast.LENGTH_LONG).show();
            //finish();
        }
    }
    @Override
    protected String doInBackground(String... params)
    {
        String usernam = username.getText().toString();
        String passwordd = password.getText().toString();
        if(usernam.trim().equals("")|| passwordd.trim().equals(""))
            z = "Please enter Username and Password";
        else
        {
            try
            {
                con = connectionclass(un, pass, db, ip);        // Connect to database
                if (con == null)
                {
                    z = "Check Your Internet Access!";
                }
                else
                {
                    // Change below query according to your own database.
                    String query = "select * from cliente where nome= '" + usernam.toString() + "' and cpf = '"+ passwordd.toString() +"'  ";
                    Statement stmt = con.createStatement();
                    ResultSet rs = stmt.executeQuery(query);
                    if(rs.next())
                    {
                        z = "Login successful";
                        isSuccess=true;
                        con.close();
                    }
                    else
                    {
                        z = "Invalid Credentials!";
                        isSuccess = false;
                    }
                }
            }
            catch (Exception ex)
            {
                isSuccess = false;
                z = ex.getMessage();
            }
        }
        return z;
    }
}


@SuppressLint("NewApi")
public Connection connectionclass(String user, String password, String database, String server)
{
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    Connection connection = null;
    String ConnectionURL = null;
    try
    {
        Class.forName("net.sourceforge.jtds.jdbc.Driver");
        ConnectionURL = "jdbc:jtds:sqlserver://" + server + database + ";user=" + user+ ";password=" + password + ";";
        connection = DriverManager.getConnection(ConnectionURL);
    }
    catch (SQLException se)
    {
        Log.e("error here 1 : ", se.getMessage());
    }
    catch (ClassNotFoundException e)
    {
        Log.e("error here 2 : ", e.getMessage());
    }
    catch (Exception e)
    {
        Log.e("error here 3 : ", e.getMessage());
    }
    return connection;
}
    
asked by anonymous 09.03.2018 / 18:31

1 answer

1

I think you're missing out on your connection string:

  ConnectionURL = "jdbc:jtds:sqlserver://" + server + database + ";user=" + user+ ";password=" + password + ";";

Should be:

  ConnectionURL = "jdbc:jtds:sqlserver://" + server + ":" + porta+";databaseName=" + database + ";user=" + user+ ";password=" + password + ";";
    
09.03.2018 / 19:12