Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EditText username1;
- EditText password1;
- TextView status;
- ResultSet rs;
- //private static final String url = "jdbc:mysql://10.0.2.2:3306/tesina";
- private static final String url = "jdbc:mysql://192.168.1.10:3306/tesina";
- private static final String user = "root";
- private static final String pass = "";
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- username1 = (EditText) findViewById(R.id.user);
- password1 = (EditText) findViewById(R.id.pass);
- //status =(TextView) findViewById(R.id.login_error);
- Button btnLogin=(Button) findViewById(R.id.btnlogin);
- btnLogin.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- new Connessione().execute();
- }
- });
- }
- private class Connessione extends AsyncTask<String, String, Void> {
- @Override
- protected Void doInBackground(String... String) {
- String us = username1.getText().toString();
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection(url, user, pass);
- Statement stmt = con.createStatement();
- rs = (ResultSet) stmt.executeQuery("SELECT * FROM prova WHERE nome='"+us+"'");
- }
- catch(Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- protected void onProgressUpdate(String... values) {
- }
- protected void onPostExecute(String result) {
- String p = password1.getText().toString();
- try {
- if(rs.next())
- {
- String dbpass = rs.getString(2);
- if(dbpass.equals(p))
- {
- Intent i = new Intent(MainActivity.this,classi.class);
- i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(i);
- finish();
- }
- else
- {
- Toast.makeText(getBaseContext(), "errore: password non inserita correttamente", Toast.LENGTH_LONG).show();
- }
- }
- else
- {
- Toast.makeText(getBaseContext(), "errore:username non trovato", Toast.LENGTH_LONG).show();
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- Toast.makeText(getBaseContext(), "applicazione non collegata al database della scuola", Toast.LENGTH_LONG).show();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement