Android Tutorial | How To Connect Android Studio With SQL Server Database | swift learn

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] welcome to my channel swiftland this tutorial i will show you how to connect sql server with android studio step by step if you don't subscribe my channel yet please subscribe and press the bell icon for upcoming videos okay first of all i'm gonna create a folder uh to create android application so the dj android project tutorial folder open and now here i'm going to create a folder for the name is connect android underscore sql okay open this folder now the folder is empty now start android studio okay click on new project new project and select empty activity click on next save location select the directory and my folder name is connect android underscore sql select ok name the application application name is connect android underscores call okay language java click on finish yes now you can see in the directory the application is created idf and gradle also okay now maximize this uh android studio okay yes this is the main activity.java now go to the activitymain.xml file design this page with button text view control to load data from sql to text using button click in that case first of all add a button resize this button yes [Music] concentrate the button in top and bottom right and left so that you can position the button default position is in the top left so say the text of this button text is load okay now the text is a load add text view [Music] yes and one more text view this is test view 2 concentrate the [Music] with fast text view and bottom right and left and this takes me also [Music] okay [Music] i'll display data from sql server database to text view using button click ok this is code of the design so change the text size android column text size equal to 25 sp okay just copy this line and paste it in text view and text view too [Music] yes all uh all text view and buttons text sizes sp okay now add a java class to connect with ms sql server so right click on the java main activity java classes name the java class our class name is connection helpful entire press enter yes the class is created now connection [Music] can and string listing you name pass enemies username of database pass password ip server ip port server tcpap for database sql server database name [Music] okay the public connection connection class okay now ip ip survivor 172.1.1.0 database database name is start sql server you see that server name is open pc and login name asset password is just custom authentication password you can connect yes it's connected expand the database expand the programming dv database table table is product underscore setup underscore tab okay my database name is programming db just copy this database name and paste it in database okay now username essay password sql server authentication password [Music] test129 and four default forties one four double three if you change your tcp ipv4 you should put your tcp port now stick mode dot thread policy policy equal to new stick mode dot thread policy dot builder policy policy okay now connection connection equal to default connection is null then [Music] return connection [Music] so now is change connection url equal to default conditional is null so now add tri kits try [Music] catch exception ex log dot e [Music] put error masses error and then display the exception x dot get messes okay now press alter shift enter to resolve this error yes it's solved now class dot for name [Music] net dot source force dot jtds.jdbc okay dot driver okay [Music] now connection url equal to [Music] jdbc colon jtds colon sql server colon double slash plus iv plus [Music] colon port [Music] semicolon then database name [Music] database name equal to and then database what i declare database programming db for on user user equal to user u name user is sql server authentication username and password is sql server application password has equal password equal to pass okay now connection equal to driver manager dot get connection connection url [Music] okay finally return the connection okay for name brush alt shift enter to resolve this if you [Music] now in the main activity dot java in this page i will create a method to to display data from sql server to text view using button click ok my text view one a text view and text view two the id of text views are text view and text bluetooth so first of all declare connection connection connect connection connect okay now string connection result equal to default connection result is blank now i'm gonna create a method method is public but get text from sql [Music] in this method i'll write code to load a data from sql server database to text view okay now text view tx1 equal to textview findview id r dot id dot text view okay copy this line of code and sim duplicate this one is for text view two and the variable name is tx2 okay now see that id is text view and second textbook view is id textview2 [Music] okay [Music] now edit tri kits catch [Music] exception ex [Music] result message error messages later okay now connection helper connection helper equal to new [Music] connection okay connect equal to connection helper dot connection class cache helper is my java class and [Music] if connect not equal to null [Music] then string query this is sql statement as well as statement to select all the records from the sql server database to android studio so my table name is product underscore set underscore tab so query select start from product underscore set of underscore tab okay now get a statement statement asked equal to connect dot clear statement [Music] now result set result set r is equal to st dot execute query query queries the sql statement finally while r is the next [Music] my text view variable is tx1 so tx1 dot settext get string for index of the database column index is one two item name index two product area in this one index one so this text view will display item name from the squarespace database table my product server underscore tab [Music] tx2.0 to if i put one then it will display the product id and two for item name okay on this f [Music] yes it's starting [Music] click on load oh it's doing nothing f is closed without any warning to get the warning at suffrazzlin go to the connection helper and add surface lint at the red suppress lint new fvi okay now see that uh jetty as jdbc we use that tsj and jdbc to connect with sql server but in that case you should add chart dependency and you should add jar file jds jar file in the project library this is my dslr file add this file in the project library so this is my project connect underscore connect android and sql sql in this library folder just copy this jar file and paste it in the library folder okay now it's done copy the location directory and with android studio go to the file menu and click on project structure okay click on dependencies and then f and under the declared dependencies click on plus sign and click on the defendants just face the directory with the file name here only the directory to get file name just copy the file name jds hyphen 1.3.1.jar copy this file name and paste it in the directory with a backslash yes now paste [Music] the file name yes it's added click on ok now open the androidmanifest.xml here you should add permission user permission android name name is androidformation.internet and second one is android permission user permission android name access network state permissions android permission dot access natural state okay now [Music] okay if connection not equal to null then it's execute now add an else statement if connection is not okay then it will display masses message will be connection result dot result equal to [Music] put your message check connection [Music] okay and my method name is get text from sql so you should select the method in the button click go to the activitymain.xml select the button and go to the on click event this is on click just select the method in the on click yes [Music] now everything is okay and enable tcp in that case go to the sql server configuration manager this is sql 2014 configuration manager open this configuration manager yes and open the sql server network configuration protocol tcp it's disabled enable this tcp yes it's enabled now we should restart sql server service so that it will work with the apply change restart yes it's restart completed now go to the android studio and run this f okay android is starting [Music] now load click on load button yes it's displaying the data product id and product name item name see that product id104 and item name left of its displaying perfectly in the android studio from the sql server database stable you can add higher clause it's default it's displaying the last record so if you use higher close higher product id equal to uh one zero two then it will display the product id and item name based on one zero two okay yes click on load yes you can see it's displaying one zero two and mouse okay this is the table name product underscore setup underscore tab and the index is uh if i change the index 2 and 3 then it will display item name and yes load item name and design let's check the sql server yes you can see it's displaying the 102 item name and design thanks for watching this tutorial you
Info
Channel: Swift Learn
Views: 61,110
Rating: undefined out of 5
Keywords: swift learn, connect android studio to sql server, how to connect android studio to sql server 2014, how to connect database in android studio, how to connect local sql server in android, connect android studio with sql server, sql server, android studio, android studio tutorial, how to connect to sql server database in android studio
Id: dYt763QgaTg
Channel Id: undefined
Length: 20min 22sec (1222 seconds)
Published: Tue Dec 22 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.