vendredi 8 mai 2015

Android Studio & SQL Server Connection Issue

I am practicing some development for Android using Android Studio and I am currently trying to establish an SQL connection between the app I'm working on and the SQL Server I have got set up on my local machine. I would like to note that I am debugging the program through my LG G2 SmartPhone.

Here is the code I've got out of the net after a long search. It's pretty much impossible for me to find anything better:

public class DB_Handler {
public static void ConnectToDatabase(){

    new Thread(new Runnable() {
        public void run() {
            try {

                // SET CONNECTIONSTRING
                Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
                String username = "DB_9C48A0_androidApp_admin";
                String password = "xx";
                Connection DbConn = DriverManager.getConnection("jdbc:jtds:sqlserver://208.118.63.19:1433/DB_9C48A0_androidApp;user=" + username + ";password=" + password);

                Log.w("Connection", "open");
                Statement stmt = DbConn.createStatement();
                ResultSet reset = stmt.executeQuery(" select * from users ");

                String s = reset.getString(1);

                DbConn.close();

            } catch (Exception e) {
                Log.w("Error connection", "" + e.getMessage());
            }
        }
    }).start();
}

}

No errors occur, my debugging just stops and the application shuts down.

Any ideas?

Aucun commentaire:

Enregistrer un commentaire