Guest User

Untitled

a guest
Oct 22nd, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. package avo.ob.movie;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. /**
  8. *
  9. * @author phoenix
  10. */
  11. public class DbConnetion {
  12.  
  13. static String bd = "TelematicsDev";
  14. static String user = "postgres";
  15. static String password = "postgres";
  16. static String url = "jdbc:postgresql://192.168.15.46/TelematicsDev";
  17. Connection connetion = null;
  18.  
  19. public DbConnetion() {
  20.  
  21. try {
  22. Class.forName("org.postgresql.Driver");
  23. /*
  24. driver=org.postgresql.Driver
  25. username=postgres
  26. password=postgres
  27. url=jdbc:postgresql://phoenixtelematics.dyndns.org/TelematicsDev
  28. url=jdbc:postgresql://192.168.15.46/TelematicsDev
  29. */
  30.  
  31. connetion = DriverManager.getConnection(url, user, password);
  32.  
  33. if (connetion != null) {
  34. System.out.println("Conexion a la BD [" + connetion + "] OK");
  35. }
  36.  
  37. } catch (SQLException ex) {
  38. System.out.println("Exception ocurrida: " + ex.getMessage());
  39. } catch (ClassNotFoundException ex) {
  40.  
  41. }
  42.  
  43. }
  44.  
  45. public Connection getConnection() {
  46. return connetion;
  47. }
  48.  
  49. public void disconect() throws SQLException {
  50. System.out.println("Cerrando conexion: " + connetion);
  51. if (connetion != null) {
  52. connetion.close();
  53. }
  54. }
  55.  
  56. }
  57.  
  58. <h:form>
  59. <h2>Peliculas</h2>
  60. <p:inputText class="borderInput ui-lg-4" id="busca" value="" style="width:20%" maxlength="100" placeholder="Buscar Pelicula" onkeypress="alfanumerico(event)"/><br/><br/>
  61.  
  62. <p:dataTable var="peliculas" value="#{movieBean.peliculas}">
  63. <p:column headerText="id_movie">
  64. <h:outputText value="#{movieBean.movies.id_movie}" />
  65. </p:column>
  66.  
  67. <p:column headerText="movie_name">
  68. <h:outputText value="#{movieBean.movies.movie_name}" />
  69. </p:column>
  70.  
  71. <p:column headerText="movie_year">
  72. <h:outputText value="#{movieBean.movies.movie_year}" />
  73. </p:column>
  74.  
  75. </p:dataTable>
  76. </h:form>
  77.  
  78. public List<moviesDTO> getMovies(String nombrePelicula) {
  79.  
  80. List<moviesDTO> listaPeliculas = new ArrayList<>();
  81. ConnectionDB conn = new ConnectionDB();
  82. List<ParametersSP> parametros = new ArrayList<>();
  83. parametros.add(new ParametersSP("string", nombrePelicula));
  84. try {
  85. ResultSet res = conn.ExecuteFunctionQuery("sp_get_peliculas", parametros);
  86. while (res.next()) {
  87. moviesDTO movies = new moviesDTO();
  88. movies.setId_movie(res.getInt(1));
  89. System.out.println("Id Pelicula..." + movies.getId_movie());
  90. movies.setMovie_name(res.getString(2));
  91. movies.setMovie_year(res.getInt(3));
  92.  
  93. listaPeliculas.add(movies);
  94.  
  95. }
  96. } catch (SQLException | IOException ex) {
  97. Logger.getLogger(MovieDAOImplements.class.getName()).log(Level.SEVERE, null, ex);
  98. }
  99.  
  100. return listaPeliculas;
  101. }
  102.  
  103. ConnectionDB conn = new ConnectionDB();
  104. List<ParametersSP> parametros = new ArrayList<>();
Add Comment
Please, Sign In to add comment