Advertisement
Guest User

jordito

a guest
Nov 29th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package control;
  7.  
  8. import java.sql.Statement;
  9. import java.sql.Connection;
  10. import java.sql.ResultSet;
  11. import java.sql.SQLException;
  12. import java.util.ArrayList;
  13.  
  14. /**
  15. *
  16. * @author Laboratorio
  17. */
  18. public class ManejadorBaseDeDatos {
  19.  
  20. private Connection conexion;
  21. private Statement instruccionSql;
  22. private ResultSet resultado;
  23. private ArrayList<String> lista;
  24.  
  25. public ManejadorBaseDeDatos() {
  26. try {
  27. Class.forName("com.mysql.jdbc.Driver");
  28. String url = "jdbc:mysql://localhost/bd_peliculas";
  29. conexion = java.sql.DriverManager.getConnection(url, "root", "root");
  30. instruccionSql = conexion.createStatement();
  31. } catch (ClassNotFoundException | SQLException ex) {
  32. }
  33. }
  34.  
  35. public ArrayList<String> obtenerPeliculas() {
  36.  
  37. try {
  38. resultado = instruccionSql.executeQuery("SELECT id_pelicula, titulo, FROM peliculas");
  39. while (resultado.next()) {
  40. lista.add(resultado.getString("titulo"));
  41. }
  42. return lista;
  43. } catch (SQLException ex) {
  44. return null;
  45. }
  46.  
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement