Guest User

Untitled

a guest
Jun 7th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. package com.example.proyectojd.login.login;
  2.  
  3. btAceptar.setOnClickListener(new View.OnClickListener() {
  4. @Override
  5. public void onClick(View view) {
  6. if (conectarMySQL()==true) {
  7. Toast.makeText(getBaseContext(), "Conexion establecida.", Toast.LENGTH_LONG).show();
  8. }else {
  9. Toast.makeText(getBaseContext(), "Conexion NO establecida.", Toast.LENGTH_LONG).show();
  10. }
  11.  
  12. }
  13. });
  14. }
  15. public boolean conectarMySQL ()
  16. {
  17. boolean estadoConexion = false;
  18. Connection conexionMySQL = null;
  19.  
  20. String driver = "com.mysql.jdbc.Driver";
  21. String urlMySQL = "jdbc:mysql://" + sv + ":" + pt + "/";
  22. Toast.makeText(this,urlMySQL + bd + " " + us+ " " + ct,Toast.LENGTH_LONG).show();
  23. try {
  24. Class.forName(driver).newInstance();
  25. conexionMySQL = DriverManager.getConnection(urlMySQL + bd ,us,ct);
  26. return true;
  27. } catch (Exception ex) {
  28. Toast.makeText(MainActivity.this,"Error al comprobar las credenciales:" + ex.getMessage(),Toast.LENGTH_LONG).show();
  29. Toast.makeText(MainActivity.this,"Error:" + ex.getCause(),Toast.LENGTH_LONG).show();
  30. return false;
  31. }
  32. }
Add Comment
Please, Sign In to add comment