MySQL的远程数据库操作的机器人 [英] MySql remote database manipulation in Android

查看:122
本文介绍了MySQL的远程数据库操作的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何访问mysql的远程不使用PHP或JSON ......或任何其他方法?

解决方案

 包com.example.login2;
    进口的java.util.ArrayList;
    进口org.apache.http.NameValuePair;
    进口org.apache.http.message.BasicNameValuePair;
    进口android.app.Activity;
    进口android.os.Bundle;
    进口android.view.View;
    进口android.widget.Button;
    进口android.widget.EditText;
    进口android.widget.TextView;

    公共类Login2身份延伸活动{
    联合国的EditText,PW;
    TextView的错误;
    OK按钮;
    / **第一次创建活动时调用。 * /
    @覆盖
    公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);
    UN =(EditText上)findViewById(R.id.et_un);
    PW =(EditText上)findViewById(R.id.et_pw);
    OK =(按钮)findViewById(R.id.btn_login);
    误差=(TextView中)findViewById(R.id.tv_error);
    ok.setOnClickListener(新View.OnClickListener(){

    @覆盖

    公共无效的onClick(视图v){
    // TODO自动生成方法存根
    ArrayList的<的NameValuePair> postParameters =新的ArrayList<的NameValuePair>();
    postParameters.add(新BasicNameValuePair(用户名,un.getText()的toString()));
    postParameters.add(新BasicNameValuePair(密码,pw.getText()的toString()));

    //字符串有效=1;
    串响应=无效;
    尝试 {
    响应= CustomHttpClient.executeHttpPost(http://engiguide.com/check.php,postParameters); // Enetr您的远程PHP,ASP,Servlet的文件链接
    字符串解析度= response.toString();
    //解析度= res.trim();
    RES = res.replaceAll(\\ S +,);
    //error.setText(res);
    如果(res.equals(1))
    error.setText(正确的用户名和密码);
    其他
    error.setText(对不起!不正确的用户名或密码);

    }赶上(例外五){

    un.setText(e.toString());
    }}
    });

}}
 

检查此链接,它解释了详细说明如何访问远程数据库如MySQL使用PHP,ASP,JSP

How can access mysql remotely without using PHP or JSON...or any other method?

解决方案

    package com.example.login2;
    import java.util.ArrayList;
    import org.apache.http.NameValuePair;
    import org.apache.http.message.BasicNameValuePair;
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;

    public class login2 extends Activity {
    EditText un,pw;
    TextView error;
    Button ok;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    un=(EditText)findViewById(R.id.et_un);
    pw=(EditText)findViewById(R.id.et_pw);
    ok=(Button)findViewById(R.id.btn_login);
    error=(TextView)findViewById(R.id.tv_error);
    ok.setOnClickListener(new View.OnClickListener() {

    @Override

    public void onClick(View v) {
    // TODO Auto-generated method stub
    ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
    postParameters.add(new BasicNameValuePair("username", un.getText().toString()));
    postParameters.add(new BasicNameValuePair("password", pw.getText().toString()));

    //String valid = "1";
    String response = null;
    try {
    response = CustomHttpClient.executeHttpPost("http://engiguide.com/check.php", postParameters);  //Enetr Your remote PHP,ASP, Servlet file link
    String res=response.toString();
    // res = res.trim();
    res= res.replaceAll("\\s+","");
    //error.setText(res);
    if(res.equals("1"))
    error.setText("Correct Username or Password");
    else
    error.setText("Sorry!! Incorrect Username or Password");

    } catch (Exception e) {

    un.setText(e.toString());
    }}
    });

}}

Check this link, it explains in detail how to access Remote DB like MySQL using PHP,ASP,JSP

这篇关于MySQL的远程数据库操作的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆