i am currently using this code for the registration:
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");
}
Yes, it would be better using json, but i neet to use this… so the code check if the email exist, i also need to check if the username exist, how can i do? I have to add another sql query or i can edit this to check also if the username exist on db?
Thanks.
This will return row if email or username exists so that you can prompt the user that login data already exists: