Android Insert Data into MySql Database Server - Android Mysql Connection

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome guys welcome to my inverter oil its come on buddy here in this video I'm going serve some data from my s from Android phone for MySQL database so first of all what I need to do is I need to set up a MySQL database server so I am installed a ram server on my local host machine whatever got a you guys are installed you guys have exam server you guys have online service so this procedure is going to work on all of them so as you guys can see here I have created a database with name this and inside there's a exist a table within this I am opening this table and in this table there's only one column with name callers for name let's go here so this column contains only one record or if already present image so what you guys have to do you guys I have to go to the privileges you guys need to add a new user to your database I'm adding a C's user and password and then retype in the password so I'm grabbing all the permissions here and I'm reading this user so you guys can see and run all that installation there just as well so database is set it up you guys need to go to the end right bar so in this part there is a two ways to connect to your database from NY you can either use a web service or you can add a user Jerry we see so Jerry we see the library which actually provides you a connection from your Android phone to your database so I'm going with the JDBC part because it's much easier and much time-saving yeah in my next tutorial I will also explain how to how to connect to your database using a web service so what I have done here I am a imprudent jar file MySQL connector Java you can download this jar file from the internet and you can you have to download this jar file in your products project by going to app a new module click into equally for jar file next and as specifying the location and less specifically after getting this our file into your project you need to compile this project as well as as you guys can see here the highlighted line you need to add this line in your dependencies after adding this you have to go to the manifest file and you have to go you have to insert you have to add the internet permission in your Android manifest file because your application is going to use Internet so after doing this we need to move to move to the layout part you need to to the activity layout part so this is the layout of my application you guys can see here at text view and edit text which you get that input from the user a button for Pharma throat and a text view this is actually that is used to show the reserves okay so you guys can go through my XML layout but this is the external layer of my application so now we need to do some Java code goes behind this XML of Java code is running so we have to open the project we have to open the main activity file so this is a Java file this is the Java file which is actually connecting you from your Android app major MySQL database so we have declared two fields a text view and edit view we have a three lines here these three lines actually defines the credentials of your database as we have created a user with a name ZZZ so we have to add this here password disease so we have to add this here so a guys you need to replace this as IP because this IP is actually the IP of my local host machine so you guys need to check your IP by going to the command form in the command prompt and typing IP on fake this would be the IP of your machine you have to specify the IP of your own machine okay so this is a hair is the database name if you if you run a base you have changed the database name so you also need to change the name air as well so now come to the oncreate method I have declared the edit text and text view that I have just inserted on the layout so this is the on create view of button because you can guys can see here I have put it it on the cleaner here in my button this line so this line is calling this function here and this function is calling actually asking tasks yessum task is actually a background thread which which runs on background okay so this these two lines are actually calling this async task and in this async task we are actually getting the input from the user that if user just have inputted okay so we have a get inure input and we have stored it in a text so in on pre execute method we have shown a result on the screen that to the user that please made inserting data and in doing background method we in these two lines these two lines are actually that connection connection creating the connection of your Android phone of your Android phone with your MySQL database so if connection is null if you show message which show connection goes wrong if connection is not null and is successful that it will insult that text that the user has input in the text field it would get that that text and it would insert this text in that database column that we just have created here you guys can sleep here here okay so in this line we are creating the connection statement and in this line we are executing the children if curiosity executed successfully and it would show in resulting successful otherwise it will show connection goes wrong and in on post execute it will show the error whether it was successful whether it was wrong and etcetera and etcetera so guys the monster one step more you need to turn off the Windows Firewall of your PC because if you don't turn off the firewall and you cannot be connected from your Android phone so let's go ahead and run this application on your device you can see the device here is actually running a two bit a line forty-four the bedroom wise guys is actually the voice of my PC spam first actually installing the apk and it will deploy this apk on this device so unless it tests this application whether it's work or not so application open we are entering some data we enter pop or wrestle the done button and clicking clicking on the insert data please wait inserting data inserting successful okay go ahead and check the database refresh it again yeah we got the database here or we can you can guys can see here we we have got a new row here so this is all guys let's add a new data in for the testing purpose inserting data clicking on ends Adira clicking on insert data inserting successful I have clicking you click it three or four times so you guys can see here at three more rows so this is all guys if you have any any questions if you have any queries you guys can comment in the comment section and I will surely reply you guys as soon as possible and thanks guys subscribe to my channel and keep watching my videos thank you guys
Info
Channel: kamran bhatti
Views: 84,923
Rating: undefined out of 5
Keywords: android insert data, android mysql connectivity, mysql connect android, mysql android, android php mysql, mysql for android, android mysql connection, android app mysql
Id: ryMj8xnZkSQ
Channel Id: undefined
Length: 9min 38sec (578 seconds)
Published: Sat Sep 03 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.