Ben Johnston
Ben Johnston

Reputation: 11

Change values to string

I am new to java and coding. I have created an app that asks the user to register their username and password to be able to log in. I have this piece of code:

 EditText username = (EditText) findViewById(R.id.RegUsername);
 EditText password = (EditText) findViewById(R.id.RegPassword);
 EditText password2 = (EditText) findViewById(R.id.RegPassword2);

 String usernamestr = username.getText().toString();
 String passwordstr = password.getText().toString();
 String password2str = password2.getText().toString();

It all works fine. I am just wondering why it has to be changed to a String to save to the database?

Upvotes: 1

Views: 58

Answers (2)

Ajinkya Patil
Ajinkya Patil

Reputation: 741

If your database is using varchar to save username and password then you need to convert to strings, because String in java are similar to varchar in DB. Whereas there is no object in DB which corresponds to EditText in Java

Upvotes: 2

Bax
Bax

Reputation: 4476

Because String has an equivalent in the database typing system (e.g. varchar) and the JDBC driver will be able to translate it to that type.
EditText doesn't.

Upvotes: 2

Related Questions