0
I’m having trouble connecting to Sql Server and Android. When I try to communicate, the message appears: "No address Associated with hostname." I’ve done everything I needed, already downloaded the Drive jtds, downloaded the sql server 2017, and could not make the communication, if anyone can give me a help, I will thank.
Full error message: Unknown server host name 'Unable to resolve host "192.168.1.3projectodendroid": 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;
}
and select host ? where is the code you are using ?
– Rovann Linhalis
I put it there now. I forgot to put it. Is it some problem in sql server version?
– Hiago Venancio
I think you’re wrong here:
+ server + database +
in the end it would be:192.168.1.3projetoandroid
and it will go wrong– Rovann Linhalis
I have already put a '/' also for forehead, I made some changes, similar type does to access the wamp, but he is just not able to recognize the hostname. I don’t know if this may be a problem with the sql server version. I’ve seen other examples that worked great, but mine is not working at all.
– Hiago Venancio
which string value at runtime ?
– Rovann Linhalis