Basicamente el video es como un minitutorial de como desarrollar una Enterprise Application
El proyecto desarrollado por mi grupo tiene las siguiente caracteristicas.
- Uso del framework ICEfaces en la capa web
- Uso de EJB 3.0 en la capa de negocios
- Uso de un Pool de conexiones para la base de datos.
- Como integrar ICEFACES en Netbeans
- Crear una Enterprise Application e integrarle el framework ICEfaces
- Crear un pool de conexiones (conexion.java) y hacer uso de él desde un EJB (capa de negocio)
- Crear un Managed Bean (en la capa web) que se comunique con el EJB.
- Hacer uso del managed bean desde un JSP.
ICEfaces + EJB 3.0 + Pool Conexiones + JEE
package genericos;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class Conexion {
Connection conn = null;
ResultSet rs = null;
public Conexion(){
}
public void conectar(){
Context c = null;
Context envCtx = null;
DataSource ds = null;
Statement stmt=null;
String sql="";
String resultado="";
try {
ds=this.getConexionBD();
conn = ds.getConnection();
if(conn== null)
System.out.println("ConexionNula");
} catch (NamingException ex) {
ex.printStackTrace();
Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
}
catch (SQLException ex) {
ex.printStackTrace();
Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
}
}
public Object ejecutaSql( String sql )
{
Statement stmt =null;
conectar();
int irs = 0;
try
{
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
if( sql.startsWith( "select" ) )
{
rs = stmt.executeQuery( sql );
//System.out.println( "xq rs: " + rs );
}
else if( sql.startsWith( "delete" ) || sql.startsWith( "insert" ) )
{
irs = stmt.executeUpdate( sql );
//rs = stmt.getGeneratedKeys();
}
else if( sql.startsWith( "update" ) )
{
irs = stmt.executeUpdate( sql );
}
}
catch( Exception e ) {
e.printStackTrace();
//throw e;
return e.toString();
}
return rs;
}
@SuppressWarnings("empty-statement")
public void close(){
if (rs != null) {
try { rs.close(); } catch (SQLException e) { ; }
rs = null;
}
if (conn != null) {
try { conn.close(); } catch (SQLException e) { ; }
conn = null;
}
}
private DataSource getConexionBD() throws NamingException {
Context c = new InitialContext();
return (DataSource) c.lookup("dataSource");
}
}