Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ANDROID:mysql JDBC中的用户登录认证_Java_Android_Mysql_Authentication_Jdbc - Fatal编程技术网

Java ANDROID:mysql JDBC中的用户登录认证

Java ANDROID:mysql JDBC中的用户登录认证,java,android,mysql,authentication,jdbc,Java,Android,Mysql,Authentication,Jdbc,我真的需要关于在android中使用MySql数据库中的JDBC库进行用户身份验证的帮助。我的数据库完全正常工作,但我不知道如何在登录活动中提供身份验证 这是我的DBHelper类 public boolean loginUser(String userName, String password) { boolean result = false; ResultSet rSet; try { PreparedStatement st = conn.pr

我真的需要关于在android中使用MySql数据库中的JDBC库进行用户身份验证的帮助。我的数据库完全正常工作,但我不知道如何在登录活动中提供身份验证

这是我的DBHelper类

 public boolean loginUser(String userName, String password) {
    boolean result = false;
    ResultSet rSet;

    try {
        PreparedStatement st = conn.prepareStatement(("SELECT username, password, member_tbl where user_name=? and password=?"));
        st.setString(1, userName);
        st.setString(2, password);

        rSet = st.executeQuery();
        result= rSet.next();

        if (result == true) {
            if (rSet.getInt("username") > 0) {
                st.close();
            }
        }

    } catch (SQLException e) {
        Log.e(TAG, e.getMessage());
    }

    return result;
}

登录活动类

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    btnLogin= (Button) findViewById(R.id.buttonLogin);
    editextUserName= (EditText) findViewById(R.id.editTextUserName);
    editextPassword= (EditText) findViewById(R.id.editTextPassword);

    btnLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (editextUserName.getText().toString().isEmpty() || editextPassword.getText().toString().isEmpty()){
                Toast.makeText(getApplicationContext(),"Please fill out needed details.",Toast.LENGTH_LONG).show();
            }else {
                new loginUser().execute();
            }
        }
    });
}

private class loginUser extends AsyncTask<Void, Void, Void> {
    ProgressDialog dialog;
    private boolean result;

    @Override
    protected void onPreExecute() {

        uName= editextUserName.getText().toString();
        pWord= editextPassword.getText().toString();

        dialog= new ProgressDialog(LoginActivity.this);
        dialog.setCancelable(false);
        dialog.setMessage("Logging in..");
        showDialog();
        result=false;
    }

    @Override
    protected Void doInBackground(Void... params) {
        DBHelper db= new DBHelper();
        result= db.loginUser(uName,pWord);
        return null;
    }

    @Override
    protected void onPostExecute(Void aVoid) {
        hideDialog();
        if (result == false) {
            toastUserLogin(uName);
        }else {
            Toast.makeText(getApplicationContext(),"An error occured.",Toast.LENGTH_LONG).show();
        }
    }

    private void showDialog() {
        if (!dialog.isShowing()) {
            dialog.show();
        }
    }

    private void hideDialog() {
        if (dialog.isShowing()) {
            dialog.dismiss();
        }
    }
}

private void toastUserLogin(String userName) {
    Toast.makeText(LoginActivity.this,"Welcome authenticated user "+ userName+ " !",Toast.LENGTH_LONG).show();
}
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u登录);
btnLogin=(按钮)findViewById(R.id.buttonLogin);
editextUserName=(EditText)findViewById(R.id.editTextUserName);
editextPassword=(EditText)findViewById(R.id.editTextPassword);
btnLogin.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
如果(editextUserName.getText().toString().isEmpty()| | editextPassword.getText().toString().isEmpty()){
Toast.makeText(getApplicationContext(),“请填写所需的详细信息。”,Toast.LENGTH\u LONG.show();
}否则{
新登录用户().execute();
}
}
});
}
私有类loginUser扩展异步任务{
进程对话;
私有布尔结果;
@凌驾
受保护的void onPreExecute(){
uName=editextUserName.getText().toString();
pWord=editextPassword.getText().toString();
dialog=新建ProgressDialog(LoginActivity.this);
对话框。可设置可取消(false);
setMessage(“登录…”);
showDialog();
结果=假;
}
@凌驾
受保护的Void doInBackground(Void…参数){
DBHelper db=新的DBHelper();
结果=数据库登录用户(uName,pWord);
返回null;
}
@凌驾
受保护的void onPostExecute(void避免){
hideDialog();
如果(结果==false){
toastUserLogin(联阿援助团);
}否则{
Toast.makeText(getApplicationContext(),“发生了错误。”,Toast.LENGTH_LONG.show();
}
}
私有void showDialog(){
如果(!dialog.isShowing()){
dialog.show();
}
}
私有void hideDialog(){
if(dialog.isShowing()){
dialog.dismise();
}
}
}
私有void toastUserLogin(字符串用户名){
Toast.makeText(LoginActivity.this,“欢迎认证用户”+用户名+“!”,Toast.LENGTH\u LONG.show();
}

任何帮助都将不胜感激。:)

onPostExecute方法的更改

  if (result == true) {
        toastUserLogin(uName);
    }else {
        Toast.makeText(getApplicationContext(),"An error occured.",Toast.LENGTH_LONG).show();
    }

onPostExecute方法中的更改

  if (result == true) {
        toastUserLogin(uName);
    }else {
        Toast.makeText(getApplicationContext(),"An error occured.",Toast.LENGTH_LONG).show();
    }

在我按照你上面所说的更改代码之后。我的应用程序似乎不接受存储在数据库中的值。此行返回的结果是什么;。。?只是为了检查我的查询是否给出响应。在我按照您上面所述更改代码之后。我的应用程序似乎不接受存储在数据库中的值。此行返回的结果是什么;。。?只是为了检查我的查询是否给出了响应。