I am new in android development and I am creating an android app.
When user click on login I should receive its data on my database.
I think I have a problem in android database connectivity: when I click on login I receive no data in my database.
I use XAMPP for database.
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, user, pass);
String result = "Database connection successful";
PreparedStatement ps = con.prepareStatement("Insert into login VALUES(?, ?)");
ps.setString(1, email.getText().toString());
ps.setString(2, password.getText().toString());
ps.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} //end of insert button calling
catch (SQLException e) {
e.printStackTrace();
}
//to Fetch the Record
//finish();
login();
}
});
As a good practice, you want to add some modularity to your application's architecture. Typically, the authentication logic will not be implemented inside your android application, but rather in a separate module. For instance, inside a PHP file that resides in your server:
You may want to have a look at this tutorial: https://www.tutorialspoint.com/android/android_php_mysql.htm
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.