I have a problem when setting the data of a stored procedure to a datatable, what happens is that I am working with jsf, primefaces, jdbc, create a java class that would be this:
package avo.ob.movie;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
*
* @author phoenix
*/
public class DbConnetion {
static String bd = "TelematicsDev";
static String user = "postgres";
static String password = "postgres";
static String url = "jdbc:postgresql://192.168.15.46/TelematicsDev";
Connection connetion = null;
public DbConnetion() {
try {
Class.forName("org.postgresql.Driver");
/*
driver=org.postgresql.Driver
username=postgres
password=postgres
url=jdbc:postgresql://phoenixtelematics.dyndns.org/TelematicsDev
url=jdbc:postgresql://192.168.15.46/TelematicsDev
*/
connetion = DriverManager.getConnection(url, user, password);
if (connetion != null) {
System.out.println("Conexion a la BD [" + connetion + "] OK");
}
} catch (SQLException ex) {
System.out.println("Exception ocurrida: " + ex.getMessage());
} catch (ClassNotFoundException ex) {
}
}
public Connection getConnection() {
return connetion;
}
public void disconect() throws SQLException {
System.out.println("Cerrando conexion: " + connetion);
if (connetion != null) {
connetion.close();
}
}
}
Here if I can successfully connect to the Bd, the problem is when I want to set the values with a method that only consults the records and those same records I want to put to the datatable of the view, this is the code of the view:
<h:form>
<h2>Peliculas</h2>
<p:inputText class="borderInput ui-lg-4" id="busca" value="" style="width:20%" maxlength="100" placeholder="Buscar Pelicula" onkeypress="alfanumerico(event)"/><br/><br/>
<p:dataTable var="peliculas" value="#{movieBean.peliculas}">
<p:column headerText="id_movie">
<h:outputText value="#{movieBean.movies.id_movie}" />
</p:column>
<p:column headerText="movie_name">
<h:outputText value="#{movieBean.movies.movie_name}" />
</p:column>
<p:column headerText="movie_year">
<h:outputText value="#{movieBean.movies.movie_year}" />
</p:column>
</p:dataTable>
</h:form>
The problem is already here, when I want the SP data to be displayed in the dataTable, this is my DAO Implement code:
public List<moviesDTO> getMovies(String nombrePelicula) {
List<moviesDTO> listaPeliculas = new ArrayList<>();
ConnectionDB conn = new ConnectionDB();
List<ParametersSP> parametros = new ArrayList<>();
parametros.add(new ParametersSP("string", nombrePelicula));
try {
ResultSet res = conn.ExecuteFunctionQuery("sp_get_peliculas", parametros);
while (res.next()) {
moviesDTO movies = new moviesDTO();
movies.setId_movie(res.getInt(1));
System.out.println("Id Pelicula..." + movies.getId_movie());
movies.setMovie_name(res.getString(2));
movies.setMovie_year(res.getInt(3));
listaPeliculas.add(movies);
}
} catch (SQLException | IOException ex) {
Logger.getLogger(MovieDAOImplements.class.getName()).log(Level.SEVERE, null, ex);
}
return listaPeliculas;
}
There is only one detail in these 2 lines:
ConnectionDB conn = new ConnectionDB();
List<ParametersSP> parametros = new ArrayList<>();
Those classes: ConectionDB and ParametersSP and another that is called executeFunctionQuery all those are used in another project of the company, since those classes represent the functionality of preparedStatement, executeQuery, in my project (practice that they let me) I want to make that sp is executed, I have been told to use the callableStatement, but I do not know how to use it, I hope and you can help me how to send that sp, it is postgresql or the same as I can adapt it to the above code and show the result in the dataTable, stay tuned if I did not understand and I'll explain it with pleasure, best regards