public String getEmailAddr() throws sqlException { Cursor mCursor = db.rawquery( "SELECT Username,Passwords FROM " + USERS_table + " WHERE EmailNO=?",null); if (mCursor != null) { if(mCursor.getCount() > 0 { //return obj1.getpassword(); } } //return false; return obj1.getpassword();}
当用户输入电子邮件地址时,必须首先检查是否存在,并使用我的活动代码发送电子邮件返回密码和用户名:
public voID onClick(VIEw v) { String EmailAddress = txtEmailAddress.getText().toString(); try { if(EmailAddress.length() > 0) { DBAdapter dbUser = new DBAdapter (RecoverPassword.this); dbUser.open(); if(dbUser.getEmailAddress(EmailAddress)) { Toast.makeText(RecoverPassword.this,"Email Successfully ",Toast.LENGTH_LONG).show(); Toast.makeText String to = txtEmailAddress.getText().toString(); //String subject = EmailAddress.getText().toString(); // String message = EmailAddress.getText().toString(); Intent email = new Intent(Intent.ACTION_SEND); email.putExtra(Intent.EXTRA_EMAIL,new String[]{ to}); email.putExtra(Intent.EXTRA_SUBJECT,"Password Recovery"); email.putExtra(Intent.EXTRA_TEXT,dbUser.getEmailAddr()); //need this to prompts email clIEnt only email.setType("message/rfc822"); startActivity(Intent.createChooser(email,"gmail :")); } else { Toast.makeText(RecoverPassword.this,"InvalID Email",Toast.LENGTH_LONG).show(); txtEmailAddress.setText(""); } dbUser.close(); } } catch(Exception e) { Toast.makeText(RecoverPassword. this,e.getMessage(),Toast.LENGTH_LONG).show(); } Please help me to check what is wrong...but there is no error but it cant return username and password to the email sent解决方法 我对你的代码感到困惑,但是当你想从Cursor获取数据时
String[] whereArgs = new String[<data>]; Cursor mCursor = db.rawquery("SELECT Username,Passwords FROM " + USERS_table + " WHERE EmailNO = ?",whereArgs); mCursor.moToFirst(); if(mCursor.getCount() > 0} { String username = mCursor.getString(0); String password = mCursor.getString(1); }
您必须使用提供从数据库返回数据的Cursor实例的getter.
编辑:
我没有注意到你使用whereArgs所以当你使用WHERE子句时,你必须具体whereArgs as String []包含将被替换的数据而不是?焦炭.
您可以使用Fo关闭数据库:
@OverrIDeprotected voID onDestroy() { super.onDestroy(); if (yourDatabase != null) { yourDatabase.close(); }}
或者在打开数据库的每个工作之后,你应该关闭()db.
总结以上是内存溢出为你收集整理的在ANDROID中通过EMAIL_ADDRESS检索SQLITE DB中的用户名和密码全部内容,希望文章能够帮你解决在ANDROID中通过EMAIL_ADDRESS检索SQLITE DB中的用户名和密码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)