0
我想做一个Android应用程序,它可以登录用户从数据库到目前为止它获得的用户,它给了我一个烤面包,当我可以登录。现在它检查每一个用户所以它为每个用户显示敬酒,例如当我输入一个有效的用户名和密码时,它会先输入错误的用户名或密码,然后登录..我知道这是因为while循环,但我不知道如何当用户名和密码错误时将其显示一次。这是我的代码Java的JDBC数据库连接登录
private void setupMessageButton() {
button = (Button) findViewById(R.id.button1);
text = (TextView) findViewById(R.id.editText1);
text2 = (TextView) findViewById(R.id.editText2);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
textje = text.getText().toString();
textje2 = text2.getText().toString();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://dbhost", "root", "dbpass");
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("SELECT * FROM vtiger_users");
while(rs.next()) {
users = rs.getObject(2).toString();
wachtwoorden = rs.getObject(3).toString();
if(textje.equals(users) && textje2.equals(wachtwoorden)) {
Toast.makeText(getApplicationContext(), "Logging in..", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Wrong username or password", Toast.LENGTH_SHORT).show();
}
}
con.close();
} catch(Exception e) {
e.printStackTrace();
}
}
});
}
非常感谢你到底是什么我在寻找! – user3112505 2014-11-24 10:55:45
Gr88 ..你可以给我一些点,如果你的查询解决了 – 2014-11-24 10:58:26
我到底该怎么做,我从来没有这样做过。 – user3112505 2014-11-24 11:05:49