Guest User

Untitled

a guest
Apr 16th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. public ArrayList<Usuario> getUsuarios(){
  2. Connection con = null;
  3. con = conexion.conecta();
  4. ArrayList<Usuario> Usuarios = new ArrayList();
  5. PreparedStatement getData = conexion.preparedStatement("SELECT IDUsuario, Nickname, Password, Email FROM usuario");
  6. ResultSet data;
  7.  
  8. try{
  9. data = getData.executeQuery();
  10. while(data.next()){
  11. id = data.getInt(1);
  12. nickName = data.getString(2);
  13. password = data.getString(3);
  14. Email = data.getString(4);
  15. Usuario usser = new Usuario(data.getInt(1), data.getString(2), data.getString(3), data.getString(4));
  16. Usuarios.add(usser);
  17. }
  18. return Usuarios;
  19. } catch(SQLException e){
  20. } return Usuarios;
  21. }
  22.  
  23. public static Connection conecta(){
  24.  
  25. Connection conecta=null;
  26.  
  27. try{
  28. Class.forName("com.mysql.jdbc.Driver");
  29. String servidor="jdbc:mysql://192.168.203.4:3306/bbdd_g1"; //conectamos a nuestra propia maquina
  30. String usuario="admin_g1";
  31. String password="a7586";
  32. //inicializamos objeto conecta, del tipo connection
  33. conecta = (Connection)DriverManager.getConnection(servidor, usuario, password);
  34.  
  35. }catch(ClassNotFoundException e)
  36. {
  37. System.out.println(e.getMessage());
  38. }
  39. catch(Exception e) //capturar el resto de exceptions
  40. {
  41. System.out.println(e.getMessage());
  42. }finally{
  43. return conecta;//como el default de los case, pero se ejecuta si o si
  44. }
  45.  
  46. }
  47.  
  48. public PreparedStatement preparedStatement(String x) {
  49. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  50. }
Add Comment
Please, Sign In to add comment