android从url读数据库,Url连接android到mysql数据库

我想从使用xampp mysql创建的localhost数据库中检索数据。Url连接android到mysql数据库

public class JASONUseActivity extends Activity {

EditText byear; // To take birthyear as input from user

Button submit;

TextView tv; // TextView to show the result of MySQL query

String returnString; // to store the result of MySQL query after decoding JSON

/** Called when the activity is first created. */

@Override

protected void onCreate(Bundle savedInstanceState) {

StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()

.detectDiskReads().detectDiskWrites().detectNetwork() // StrictMode is most commonly used to catch accidental disk or network access on the application's main thread

.penaltyLog().build());

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

byear = (EditText) findViewById(R.id.editText1);

submit = (Button) findViewById(R.id.submitbutton);

tv = (TextView) findViewById(R.id.showresult);

// define the action when user clicks on submit button

submit.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

// declare parameters that are passed to PHP script i.e. the name birth year and its value submitted by user

ArrayList postParameters = new ArrayList ();

// define the parameter

postParameters.add(new BasicNameValuePair("birthyear", byear.getText().toString()));

String response = null;

// call executeHttpPost method passing necessary parameters

try {

response = CustomHttpClient.executeHttpPost("http://localhost/jasonscript.php", postParameters);

// store the result returned by PHP script that runs MySQL query

String result = response.toString();

我无法在textview中查看数据。网址是否正确?

这里是位于XAMPP的jasonscript.php/htdocs目录

$db_host = "localhost";

$db_uid = "root";

$db_pass = "";

$db_name = "";

$db_con = mysql_connect($db_host, $db_uid, $db_pass) or die('could not connect');

mysql_select_db($db_name);

$sql = "SELECT * FROM people WHERE birthyear > '" . $_POST["birthyear"] . "'";

$result = mysql_query($sql);

while ($row = mysql_fetch_assoc($result))

$output[] = $row;

print(json_encode($output));

mysql_close();

?>

我已经给网络许可清单文件。

在此先感谢。

+0

我认为Android没有错误?你能否确认(可能你没有得到强制关闭,因为你有一个try/catch)。如果Anrdoi没有错误 - 检查你的服务器是否出错 - 右键点击并转到apache - 错误日志。如果有任何错误,请运行您的应用程序,并从当时的日志中获取最后一行。 –

2013-05-08 06:38:14

+0

连接电脑的IP不是本地主机 –

2013-05-08 06:46:00

+0

没有该应用程序不强制关闭。在Apache错误日志中没有错误。我在logcat中遇到了严格的模式错误。 –

2013-05-08 08:53:31

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值