2

I'm beginner in adnroid studio,i want write simple application to connect sql server and read any table and close connection,i read this tutorial:
how to connect MS SQL
i write step by step up link,but i get this error when fire log in button i get this error:

java.lang.NullPointerException
            at com.example.nothing.myapplication.MainActivity$1.onClick(MainActivity.java:52)
            at android.view.View.performClick(View.java:3511)
            at android.view.View$PerformClick.run(View.java:14105)
            at android.os.Handler.handleCallback(Handler.java:605)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4424)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
            at dalvik.system.NativeStart.main(Native Method)


in this line:

st = connect.createStatement();


my connection string in android is this:

ConnectionURL = "jdbc:jtds:sqlserver://" + "192.168.36.171" + ";"
                    + "databaseName=" + "HYPER" + ";user=" + "razzaqi"
                    + ";password=" + "beh1368421" + ";";


how can i solve that?thanks.

behzad razzaqi
  • 1,503
  • 2
  • 18
  • 33
  • 2
    You really don't want to connect directly to a database from a user application. Hardcoding user credentials for a database directly in the app is never a good idea. Create an API that you can call via https that handles the database queries. – Gerald Schneider Sep 22 '15 at 11:29
  • are you have any link for another api?thanks my friend – behzad razzaqi Sep 22 '15 at 11:36
  • 1
    *are you have any link for another api?* --> [Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam.](http://stackoverflow.com/help/on-topic) – 2Dee Sep 22 '15 at 11:46

1 Answers1

0

My guess is that

connect = ConnectionHelper(username, password, db, ipaddress);

returns null.

I have to suggest you to use something like that http://www.tutorialspoint.com/android/android_php_mysql.htm

gmetax
  • 3,853
  • 2
  • 31
  • 45