creating a connection between MS SQL database and Android

trying to create a connection between MS SQL database and Android but emullator showing messAGE 'Unfortunately your app has stopped'.

this is the Logcat:
08-10 15:34:50.000  19410-19410/? I/art﹕ Not late-enabling -Xcheck:jni (already on)
08-10 15:34:50.700  19410-19422/ I/art﹕ Background sticky concurrent mark sweep GC freed 6621(494KB) AllocSpace objects, 6(210KB) LOS objects, 0% free, 1917KB/1917KB, paused 56.105ms total 184.819ms
08-10 15:34:50.722  19410-19422/ W/art﹕ Suspending all threads took: 21.392ms
08-10 15:34:50.853  19410-19422/ W/art﹕ Suspending all threads took: 32.373ms
08-10 15:34:50.969  19410-19410/ E/Error﹕ Single-Sign-On is only supported on Windows. Please specify a user name.
08-10 15:34:50.996  19410-19438/ D/OpenGLRenderer﹕ Use EGL_SWAP_BEHAVIOR_PRESERVED: true
08-10 15:34:51.009  19410-19410/ D/﹕ HostConnection::get() New Host Connection established 0xb3ff01b0, tid 19410
08-10 15:34:52.132  19410-19410/ D/Atlas﹕ Validating map...
08-10 15:34:52.229  19410-19438/ D/﹕ HostConnection::get() New Host Connection established 0xb3ff04f0, tid 19438
08-10 15:34:52.279  19410-19438/ I/OpenGLRenderer﹕ Initialized EGL, version 1.4
08-10 15:34:52.393  19410-19438/ D/OpenGLRenderer﹕ Enabling debug mode 0
08-10 15:34:52.474  19410-19438/ W/EGL_emulation﹕ eglSurfaceAttrib not implemented
08-10 15:34:52.474  19410-19438/ W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xb3f1d8a0, error=EGL_SUCCESS
08-10 15:35:34.777  19410-19410/ E/Error﹕ Single-Sign-On is only supported on Windows. Please specify a user name.
08-10 15:35:34.778  19410-19410/ D/AndroidRuntime﹕ Shutting down VM
08-10 15:35:34.778  19410-19410/ E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process:, PID: 19410
    java.lang.NullPointerException: Attempt to invoke interface method 'java.sql.Statement java.sql.Connection.createStatement()' on a null object reference
            at android.view.View.performClick(
            at android.view.View$
            at android.os.Handler.handleCallback(
            at android.os.Handler.dispatchMessage(
            at android.os.Looper.loop(
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(
08-10 15:35:40.955  19410-19410/? I/Process﹕ Sending signal. PID: 19410 SIG: 9 code:
public class MainActivity extends AppCompatActivity {

    Button loginbtn;
    TextView errorlbl;
    EditText edname, edpassword;
    Connection connect;
    PreparedStatement preparedStatement;
    Statement st;
    String ipaddress, db, username, password;

    private Connection ConnectionHelper(String user,String password,String database, String server)
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        Connection connection = null;
        String ConnectionURL = null;
        try {
            ConnectionURL = "jdbc:jtds:sqlserver://" + server + "/database name =" + database + ";user =" + user + ";password =" + password ;
            connection = DriverManager.getConnection(ConnectionURL);
        catch (SQLException se)
            Log.e("Error", se.getMessage());
        catch (ClassNotFoundException e)
        catch (Exception e)
        return connection;

    protected void onCreate(Bundle savedInstanceState) {

        loginbtn = (Button) findViewById(;
        errorlbl = (TextView) findViewById(;
        edname = (EditText) findViewById(;
        edpassword = (EditText) findViewById(;

        ipaddress = "";
        username = "";
        password = "";
        db = "DKMobile";

        connect = ConnectionHelper(username,password,db,ipaddress);
        loginbtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                    connect = ConnectionHelper(username, password, db, ipaddress);
                    st = connect.createStatement();
                    ResultSet rs = st.executeQuery("Select * from DKMUsers where user_ID = '"+ edname.getText().toString()+"'and Password = '"+edpassword.getText().toString()+"'");
                    if(rs!=null &&{
                        Intent i = new Intent(MainActivity.this,MainActivity.class);
                    else {
                        errorlbl.setText("Sorry, wrong credentials!!!");


                }catch (SQLException e)
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris HarteThaumaturgeCommented:
Your connection helper is returning null. Check you are using the correct ports in your ip address and add some semi-colons to server and password
CConnectionURL = "jdbc:jtds:sqlserver://" + server + ";"
                            + "databaseName=" + database 
                            + ";user=" + user
                            + ";password=" + password + ";";

Open in new window

As a side note, it is considered bad practise to access a database directly from an app. Consider using a service to connect the two.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ankurdkAuthor Commented:
hello sir

i have checked the ip address and have changed the ConnectionURL statement. Still the problem remains the same.

thanks for giving your valuable time.
Chris HarteThaumaturgeCommented:
I missed a slash from databaseName, try this

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

Open in new window

Olajire Awoyemi AborisadeCommented:
am having the same problem thought am using MSSQL 2016
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.