Java JDBC数据库连接登录
我正在尝试制作一个android应用程序,它可以与数据库中的用户一起登录,到目前为止,它得到了用户,当我可以登录时,它会为我干杯。现在它检查每个用户,所以它显示为每个用户祝酒,例如,当我输入一个有效的用户名和密码,它会首先说错误的用户名或密码,然后登录。我知道这是因为while循环,但我不知道如何在用户名和密码错误时让它显示一次。这是我的密码Java JDBC数据库连接登录,java,android,mysql,jdbc,Java,Android,Mysql,Jdbc,我正在尝试制作一个android应用程序,它可以与数据库中的用户一起登录,到目前为止,它得到了用户,当我可以登录时,它会为我干杯。现在它检查每个用户,所以它显示为每个用户祝酒,例如,当我输入一个有效的用户名和密码,它会首先说错误的用户名或密码,然后登录。我知道这是因为while循环,但我不知道如何在用户名和密码错误时让它显示一次。这是我的密码 private void setupMessageButton() { button = (Button) findViewById(R.id.
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();
}
}
});
}
更新您的查询,如 从vtiger_用户中选择*其中user=user,password=pass
非常感谢你,这正是我想要的!我以前从来没有这样做过。@user3112505这里是关于的信息。