All pastes #28891 Raw Edit

ClaseDAo

public java v1 · immutable
#28891 ·published 2005-11-16 11:32 UTC
rendered paste body
package chipbip.business.dao;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.LinkedList;import java.util.List;import org.apache.log4j.Logger;import chipbip.business.vo.AlumnoVO;import es.princast.framework.facilities.dao.PrincastDAOHelper;import es.princast.framework.facilities.dao.PrincastSQLException;/** * @created 26-oct-2005 11:58:46 * @version 1.0 */public class AlumnoDAOImpl implements  AlumnoDAO  {	private Connection connection;	protected static Logger logger = Logger.getLogger(AlumnoDAOImpl.class);	protected static PrincastDAOHelper helper = new PrincastDAOHelper (AlumnoDAOImpl.class);		/**	 * 	 * @param conn    conn	 */	public AlumnoDAOImpl(Connection conn){		this.connection=conn;	}	public List getListaAlumnos() {		List listaAlumnos = new LinkedList();		ResultSet rs = null;		AlumnoVO alumno = null;		try {			rs = helper.executeQuery("getListaAulas",null,new Object[]{},this.connection);			while (rs.next()) {				alumno = new AlumnoVO();								alumno.setApellido1(rs.getString("apellido1"));				alumno.setApellido2(rs.getString("apellido2"));				//etc			}					} catch (SQLException se) {			logger.error("Error de BD: "+se.getMessage());			throw new PrincastSQLException (se,"error de getListaAlumnos", se.getMessage());		}finally {			try {				if (rs != null){					Statement stmt = rs.getStatement();					stmt.close();				}							} catch (SQLException se) {				logger.error("Error de BD: "+se.getMessage());				throw new PrincastSQLException (se,"error de getListaAlumnos", se.getMessage());			}		}		return listaAlumnos;	}	public AlumnoVO getDetalleAlumno(int idAlumno) {		ResultSet rs = null;		AlumnoVO alumno = null;		try {			rs = helper.executeQuery("getDetalleAlumno", null, new Object[] { new Integer(idAlumno) }, connection);			if (!rs.next()) {				throw new SQLException("Aula con id " + idAlumno + " no encontrado");			}			alumno = new AlumnoVO();			alumno.setIdAlumno(rs.getInt("idAlumno"));			//etc					} catch (SQLException se) {			logger.error("Error de BD: " + se.getMessage());			throw new PrincastSQLException(se,"error de getDetalleAlumno", se.getMessage());		} finally {			try {				if (rs != null) {					Statement stmt = rs.getStatement();					rs.close();					if (stmt != null) {						stmt.close();					}				}			} catch (SQLException se) {				logger.error("Error de BD: " + se.getMessage());				throw new PrincastSQLException(se,"error de getDetalleAlumno", se.getMessage());			}		}		return alumno;		}	public void insertAlumno(AlumnoVO alumno) {		//TODO actualizar campos		//helper.executeUpdate("insertAlumno", new Object[] { "idAula", "plazas", "idCentroFormacion"}, new Object[] { new Integer(aula.getIdAula()),new Integer(aula.getPlazas()), new Integer(aula.getIdCentroFormacion()) }, connection);			}	public void updateAlumno(AlumnoVO alumno) {		//TODO actuaalizar campos		//helper.executeUpdate("updateAlumno", new Object[] { "idAula", "plazas", "idCentroFormacion"}, new Object[] { new Integer(alumno.getIdAlumno()),new Integer(aula.getPlazas()), new Integer(aula.getIdCentroFormacion()) }, connection);			}	public Connection getConnection() {		return this.connection;			}		public void closeConnection(){		try {			if ((this.connection != null) && (!this.connection.isClosed())) {				this.connection.close();				this.connection = null;			}		} catch (SQLException e) {			logger.error("Error de BD: " + e.getMessage());			throw new PrincastSQLException(e,"error de closeConnection", e.getMessage());		}	}}