This video shows the detailed steps to install and configure the MS SQL Server and Microsoft SQL Server Management Studio on your machine.
It shows the steps of how to boot up the (start) SQL services and then enable it (in SQL Server Configuration) to listen on a tcp/ip port. It uses local ip address and default port to connect to the SQL Server.
Later it shows how to use MS SQL Server Management Studio (SSMS) to create a new login ID (and password). It uses the new credentials to create new database and table and insert values in it.
Then it switches to Android Studio to show in simple steps of how to develop an App to interact with the MS SQL Server and database. It implements the required driver in the App’s gradle file of the project. It defines the required INTERNET permission in the manifest file. And then in java code it creates a Connection which is used for quering to the database.
The complete source code of this project is available at the below url:
https://programmerworld.co/android/how-to-connect-to-ms-sql-server-database-from-your-android-app-complete-steps/
For any questions, suggestions or appreciations, please reach out to us at:
https://programmerworld.co/contact/ or write to us at: [email protected]
Java code is placed below also for reference:
package com.example.mymssqlserverdatabaseconnection;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.widget.TextView;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class MainActivity extends AppCompatActivity {
private TextView textView;
private static String ip = “192.168.1.101”;
private static String port = “1433”;
private static String Classes = “net.sourceforge.jtds.jdbc.Driver”;
private static String database = “testDatabase”;
private static String username = “test”;
private static String password = “test”;
private static String url = “jdbc:jtds:sqlserver://”+ip+”:”+port+”/”+database;
private Connection connection = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.INTERNET}, PackageManager.PERMISSION_GRANTED);
textView = findViewById(R.id.textView);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
try {
Class.forName(Classes);
connection = DriverManager.getConnection(url, username,password);
textView.setText(“SUCCESS”);
} catch (ClassNotFoundException e) {
e.printStackTrace();
textView.setText(“ERROR”);
} catch (SQLException e) {
e.printStackTrace();
textView.setText(“FAILURE”);
}
}
public void sqlButton(View view){
if (connection!=null){
Statement statement = null;
try {
statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(“Select * from TEST_TABLE;”);
while (resultSet.next()){
textView.setText(resultSet.getString(1));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
else {
textView.setText(“Connection is null”);
}
}
}
–
I have connect my android app to Sal server and save images in table but it is very slow .
It takes around 5 seconds to show each image.
How can I develope my app to be like whatsapp to show data offline from local database and retrieve also from remote Sql server database
Is it secure to connect db directly like this?
Love you man ♥ FROM Colombia
Super…Working
How can I connect on encrypted sql password?
Greetings,
I have follow your sql connection string guide, I have develop one waiter app which is run on localhost. It is working properly if I install apk directly. but if i install via play store, I can not login. Can you help me about this.
I have Implement this code in my app. I have install build apk on my android it working well. but After store .aab file on play store and then download and install . I can not login. Can any help to me?
Not able to run the app on phone…..
it display connection lost.
how to run/test this app on android phone
Sir background video recorder app se hum Jo video record karte hain vo video app banane wale ke pass bhi save hota hai kya
thank you so muchhhhhhhhhhhh
Thanks for sharing, for those who still cant connect to MSSQLSERVER. DO THIS : go to file Project Structure——-select dependencies—-declare dependencies –click "+ "(plus)——-select 2) JAR/AAR dependency .ADD THE JAR FILE " jtds-1.3.1.jar "to your current project C:UsersUSERAndroidStudioProjectsMYMSSQLSERVERDATABASECONNECTIONapplibs (this info can refer from other youtube how to add dependency)
thanks for the tutorial. Will this still work for a remote linux server? what are the process/steps that I should take?
Hi, my name is Rifqi and I come from Indonesia, currently in my country everyone is playing Higgss domino island, can you make cheatss / mod apkk / tricks tricks that are not detected and can used in the game? please help sir, so that our family life can change, good luck,.
hello im new to this android studio and this sql thing. After following your tutorial and run it on my device and got FAILURE, may I know what is the problem and how can I solve it ?
Hello friend. I already have a database on hosting and how can I connect to it. Please help me
I followed all the steps but have an error in SQLException. It shows "Login failed for user 'test' ". Can you help me? Thank you!
nice update dear friend , big like done for ur video , nice share , have a nice day , stay connected
I cant connect with SQL server authentication 🙁 what do ı do
Excellent, thank you !
oh my fking god i did it
u help me so much man, after several hours struggling this shjt
anyway a very detailed tutorial video like this is very helpful
thank u so much
Its really cool, dude! Thanks
Thanks man. This video so great that you have show data from SQL to textview in app Android. But now 2021, I have try many way, it really not workings that when I click button, no event listener appears. Can you help me? Thanks a lot.
hey my friend i get an error at the same line where i write the getconnection function
Great
Work Keep it UP ❤️❤️❤️❤️
It is working smoothly if app and Sql server on the same network but not working if MS SQL server and phone are not on the same network? How can i do that?
Hi, what if i would like get all the value of C1 column? pls help
Beginner here, I dont see any build.gradle(Mobile app)?? why?
thanks in advance
great video!
dear this app on ms sql server developer instance hanging ?? any help
God Bless you <3
Hi Thanks for the info. One question, how can we host the created sql server database to internet and can use it from multiple devices that this app installed…
I can say only PERFECT 👌
It totally work from the emulator in my computer , but I get Failure whenever I tried to run the app in my real phone. Please help , why is that?
Hello there,
I wonder what would we do if the server IP changes in PROD version? We usually hire db server from a hosting company . So, they do not guarantee IP won't change. Any clue about that?
Hi sir. how can i connect my android app outside my LAN connection? thank you.
channel subscribed 🙂
sir plz make a video on login and signup page connected from ms-sql database
What can I do to write each line separately in text views?