我目前正在使用此代码进行注册:
value1 = registerEmail.getText().toString();
value2 = registerPassword.getText().toString();
value3 = registerName.getText().toString();
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, user, pass);
Statement st = con.createStatement();
Log.d("Connectc","executing check");
ResultSet res = st.executeQuery("SELECT * FROM user where email='"+value1+"'");
while (res.next()) {
userc = res.getString("email");
}
if (value1.equals(userc)) {
tv.setText("Email already in use!");
}
else{
Log.d("Connectc","registering");
st.executeUpdate("INSERT INTO user (email, password, name) VALUES('"+value1+"', '"+value2+"', '"+value3+"' )");
tv.setText("Data is successfully saved." );
Intent i = new Intent(getApplicationContext(),
LoginActivity.class);
startActivity(i);
finish();
Log.d("Connectl","pfffffffff");
}
是的,使用 json 会更好,但我需要使用它......所以代码检查电子邮件是否存在,我还需要检查用户名是否存在,我该怎么办?我必须添加另一个 sql 查询,或者我可以编辑它以检查用户名是否存在于数据库中?谢谢。