I've got a simple database out on my GoDaddy account and I'm trying to retrieve data from it. I've set up a simple php file out on my account and can call it directly from a browser and it shows the retrieved data just fine. You can see it/run it here:
http://thunderbirdtechnology.com/SnapVest/php/SnapVestDatabaseRetrieveAvailableOptions.php
You'll get the following displayed:
[
{
"ID": "1",
"CompanyName": "Yahoo Inc.",
"DateInvestStart": "2014-02-19 14:35:56",
"DateInvestEnd": "2014-02-28 11:35:44",
"DatePurchase": "2014-03-11 11:35:51"
}
]
All well and good.
But then I'm trying to do that from my JAVA program running on my ANDROID phone. And it doesn't work. Here's the section of code:
InputStream inputStream = null;
String result = "";
try
{
HttpClient httpclient = new DefaultHttpClient();
// Here is where we specify where our php file (see sample above) is that will do the actual
// gathering up of the data.
HttpPost httppost = new HttpPost("http://www.ThunderbirdTechnology.com/SnapVes/php/SnapVestDatabaseRetrieveAvailableOptions.php");
HttpResponse httpresponse = httpclient.execute(httppost);
HttpEntity httpentity = httpresponse.getEntity();
inputStream = httpentity.getContent();
}
catch(Exception e)
{
// Report "Error in http connect to database"
Toast.makeText(getBaseContext(),
"Error in http connect to database", Toast.LENGTH_LONG).show();
}
try
{
// Convert response to string
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"),8);
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null)
{
stringBuilder.append(line + "
");
}
inputStream.close();
result = stringBuilder.toString();
}
catch(Exception e)
{
// Report "Error converting result"
Toast.makeText(getBaseContext(),
"Error converting result", Toast.LENGTH_LONG).show();
}
It does indeed retrieve some data. But here's the WEIRD PART! It's NOT retrieving my data from my database table. Instead, it's retrieving some ODD FILE from I-don't-know-where!
HERE'S A SAMPLE OF WHAT IT'S RETRIEVING:
<!--
Copyright 2003, CyberTAN Inc. All Rights Reserved
This is SOURCE CODE of CyberTAN Inc.
the contents of this file may not be disclosed to third parties,
copied or duplicated in any form without the prior written
permission of CyberTAN Inc.
This software should be used as a reference only, and it not
intended for production use!
THIS SOFTWARE IS OFFERED "AS IS", AND CYBERTAN GRANTS NO WARRANTIES OF ANY
KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. CYBERTAN
SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE
-->
<HTML><HEAD><TITLE></TITLE>
<meta http-equiv="expires" content="0">
<meta http-equiv="cache-control" content="no-cache">
What the heck is THAT? I have no clue who/what CyberTan is. Why am I not getting the data from my database? It seems to be connecting to it OK. It seems to be executing the php file OK, but what it actually returns is from some file I've never seen.
I'm totally confused. :)