Android - Getting information from online database

I have created online database consisting of a table with four rows, KEY_ID, KEY_SLOT_NAME, KEY_AVAILABLE_SLOT, and KEY_TOTAL_SLOT.

Each of them has their own rows and assigned a default value and only KEY_AVAILABLE_SLOT will have its values changed.

I've created the JSONFunctions class

public class JSONfunctions { public static JSONObject getJSONfromURL(String url) { InputStream is = null; String result = ""; JSONObject jArray = null; // Download JSON data from URL try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); } catch (Exception e) { Log.e("log_tag", "Error in http connection " + e.toString()); } // Convert response to string try { BufferedReader reader = new BufferedReader(new InputStreamReader( is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result = sb.toString(); } catch (Exception e) { Log.e("log_tag", "Error converting result " + e.toString()); } try { jArray = new JSONObject(result); } catch (JSONException e) { Log.e("log_tag", "Error parsing data " + e.toString()); } return jArray; } }

As from How to connect Android app to MySQL database?

Now I'm stuck with fourth step which is to read the JSON Tag because I don't understand what that is.

Here's a sample code usage back when I was using my offline db for testing :

final TextView parkAvaliableA = (TextView) findViewById(; parkAvaliableA.setText("Available Slot : " + SlotA.available_slot); Button buttonA = (Button) findViewById(; buttonA.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if(SlotA.available_slot == 0) { Toast.makeText(getApplicationContext(), "Parking slot A is full", Toast.LENGTH_SHORT).show(); } else { SlotA.available_slot -= 1; db.updateSlot(new ParkingSlot()); } //parkAvaliableA.setText("Available Slot : " + SlotA.available_slot); Intent myIntent = new Intent(MainMap.this, ParkA.class); MainMap.this.startActivity(myIntent); } });

I need basic update operation for my database so that I can update the KEY_SLOT_AVAILABLE value every button press..

And one OOT question if I may : "Should I write KEY_ in every db column? Or it's just a hassle? I started using KEY_ when I read some online tutorials use KEY_"

-------------Problems Reply------------

You need to write a script as shown below to connect to a MySql Database:

$servername = "Your_Server_Name";
$username = "Your_UserName";
$password = "Your_Password";
$dbname = "Your_DB_Name";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);

After successful connection to the database you can perform all db operations with the server.

Check the following links you will get an idea:

Hope this helps.

Category:android Views:13 Time:2018-08-28
Tags: mysql android

Related post

  • How do I get information from a database to a session? 2012-02-23

    I want to start a new PHP session by using information in a database, but I don't know how. Help? Thanks. For example, I have DatabaseA that has TableB, with RowC. I want to store RowC's firstname into a PHP session. How do I do that? --------------S

  • Is it possible to get information from different database with inner join having database in SQL and mySql? 2011-06-10

    I have my project A with mySql database and I have another project B with msSql. I have connected the database from A and fetched data from B. But now I need to use inner join for tables in A and B. Is it possible to do so with databases in the same

  • how to postback and show a div on hover and get information from the database 2011-12-13

    I use ASP.NET, and would like to list a set of results in a table. The table will have output a link of people's name which are generated from the database. What I would like is when you hover over the link, then it would display a small div which wi

  • Correctly getting information from SQLite database 2011-04-10

    I am pretty new to Objective C, and even brand new to using SQL inside my apps. I am trying to get a running count of the state of items in my database. If you can imagine a todo type app, with a number of items in each category. The method below fir

  • How to get information from two database tables at once? (MySQL) 2011-09-17

    I want to show top rated articles on one of my website pages, but there is an issue. I have all article text, author, date, time etc. in one table called stories, and I have vote results in another table called votes. The problem is that, when I get

  • Problem getting information from the database 2010-11-25

    I am using the following query function footGames() { global $database; $q = "SELECT name FROM ".TBL_GAME." WHERE active = '1' AND type = 'soccer'"; return mysql_query($q, $database->myConnection); } The $database->myConnection is the following

  • get information from database sqlite 2011-03-31

    how to get an information from the database. I want to execute this line String nom = db.execSQL("select name from person where id='+id+'"); Can any one correct me this line to get the name of person from the table person --------------Solutions-----

  • Practises for getting information from $_GET/$_POST and saving it to a database? 2011-04-21

    What are today's best practises when it comes to getting information from a get/post and saving information to a database? Is data still escaped like it used to or are there additional practises? Also, where can HTMLPurifier fit in this? I'm currentl

  • Get hardware information from a database server 2011-09-13

    I want to get hardware information from a database server, which may not be in my private network, like the network card's MAC address, or the CPU ID. It has to work on MS SQL and MySQL. It is needed for some kind of Licensing Model and needs to work

  • Get item from SQLite database with use OnItemClickListener in Android 2011-11-28

    I want to get item from my database when i use OnItemClickListener in my ListView, but i don't know the syntax how to do that. The other say i must implement onListItemClick method, i try to use that but i got force close, maybe my syntax is just wro

  • Getting information from OrientationEventListener manually on Android 2012-01-19

    I am using OrientationEventListener to get information from orientation sensor. I am @Overriding the onOrientationChanged(int orientation) method and everything is working great. There is only one small problem, if the app is launched and the orienta

  • I want to make a working xml file in php (encoding properly) to export data from online database to iphone 2011-12-21

    I want to make a working xml file in php (encoding properly) to export data from online database to iphone please tell me the coding of i am new to php...don't know much :( please help me :( The code which I am using right now is following:

  • Parse::RecDescent - getting information from it 2009-06-04

    I'm working with the Parse::RecDescent parser in Perl, and I seem to have the most terrible time getting information from it. The information readily available online does not seem to have non-trivial examples. Here is the code: event_function: objec

  • RESTful APIs in Django for GETTING information from a server 2009-10-02

    Any idea of a RESTful APIs in Django for GETTING information from a server? What I want to do is fetch the errors from the server into a database. For example: The Live server has, any thing goes wrong with that website should POST

  • Getting information from the server for a Gadget (Vista/7) 2010-01-28

    I want to get some information from my database and show into my sidebar gadget (i am newbee on gadget coding). I tried many ways to do it but i didn't succeed yet. For this purpose, I have prepared a php file to get some values from my database (on

  • Getting information from logCat window 2011-03-16

    How to get information from the LogCat window? --------------Solutions------------- If you add something like Log.v("tag", "value"); in your code, You can see that in LogCat window. You can click Windows ->ShowView->Other-> Android ->Logc

  • Jquery/ Javascript getting information from PHP scope issue? 2011-07-06

    I am trying to get some information from our database and then use it in javascript/JQuery and I think I might be doing something wrong with the scope of the coding. Here is the current segment of code on my phtml page (magento) <script type="text

  • Getting information from different tables [Best Practice] 2011-07-15

    I have a MySQL database that I have to get information from, said information is spread across different tables and I have been googling for a while for the best method to get this information and found quite some information, but I was wondering if

  • Ordering retrieved information from a database 2011-07-25

    I'm creating a feed by retrieving information from my database using nested while loops (is there a better way to do this?). I have one table called users with all the names amongst other things. The other table is called messages which has messages,

  • Getting infrmation from MySql database from Java server to client 2012-03-17

    I have been strugling to get the client and server to send and recieve the right information. The program should be able to send a query from the client to the server. The server should then retrive the necessary information from the database and sen

  • How do I get information from another website 2012-04-22

    I would like to be able to get recent tweets of an individual from their page. Is there anyway I can do this? I'm sorry if this isn't enough informations, but I don't even know where to get started and I couldn't find anything else online to help. --

  • getting information from another file 2012-08-16

    I have one individual file for each employee that I use to figure wage and fringes for the fiscal year. I create a new tab for each year (for each employee) to keep the history and because each year the percent of one fringe changes and the insurance

  • Getting information from one form to another 2012-10-15

    Hello Experts, Let's say I have an (Orders) form and there's a (Rep) field. I would like to click a button next to the REP field label to open another form which I call "Authentication" The form is a simple dialogue which has the following fields: Us

  • Accessing information from a database using Ajax via dynamically created table using cell click event 2012-10-28

    I have a dynamically created table using html PHP and Mysql. I want to use Ajax to retrieve information from the database. The nearest example I have found to what I want to do is but this uses a dro

Copyright (C), All Rights Reserved.

processed in 0.092 (s). 11 q(s)