Reputation: 115
I'm tired of searching with no result i don't know where the problem come from , i'm trying to connect my android app with the local SQl server 2008, now i get unable to get information from sql server. please help this is my code :
String url = "jdbc:jtds:sqlserver://10.0.2.2:1433/lear_db;instance=SQLEXPRESS;";
TextView coucou = new TextView(this);
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
java.sql.Connection connexion =
DriverManager.getConnection(url,"kamal","kamal1234");
coucou.setText("Connection successful");
} catch ( SQLException e) {
// TODO Auto-generated catch block
coucou.setText("error1" + e.getMessage());
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
coucou.setText("error2" + e.getMessage());
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
coucou.setText("error0" + e.getMessage());
e.printStackTrace();
}
setContentView(coucou);
Upvotes: 1
Views: 6935
Reputation: 115
This is the connexion string that worked for me :
"jdbc:jtds:sqlserver://"+ adresseip +":1433/lear_db;user=youruser;password=yourpass"
than i got an other error wich is : android.os.NetworkOnMainThreadException
the solution is to use AsyncTask this is a tutorial : http://droidapp.co.uk/2011/05/12/android-dev-pre-loading-with-asynctask/
now i'm having a new error ( This errors never ends ) :
Unknow server host name 'unable to resolve host
Than it worked , on wifi with ip adresse of the host .
Upvotes: 1
Reputation: 92
Usually, I use jdbc:sqlserver in this fasion
String url = "jdbc:sqlserver://10.0.2.2:1433/lear_db;instance=SQLEXPRESS;";
or alternatively if using jtds, try:
String url = "jdbc:jtds://10.0.2.2:1433/lear_db;instance=SQLEXPRESS;";
Upvotes: 0