FondoPensionMysqlDAO.java 2.74 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
package trismegistoplanilla.mysqldao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.json.JSONArray;
import org.json.JSONObject;
import trismegistoplanilla.beans.FondoPensionBean;
import trismegistoplanilla.dao.FondoPensionDAO;
import trismegistoplanilla.utilities.ResponseHelper;
import trismegistoplanilla.utilities.Variables;

public class FondoPensionMysqlDAO implements FondoPensionDAO {

	@Override
	public JSONObject listarFondoPension() {
18
		System.out.println("FondoPensionMysqlDAO: listarFondoPension");
19 20 21 22 23 24 25 26 27
		JSONObject jsonListarFondoPension = null;
		JSONArray jsonArrayListarFondoPension = new JSONArray();
		Connection connection = null;
		PreparedStatement ps = null;
		ResultSet rs = null;

		ResponseHelper response = new ResponseHelper();

		try {
28
			connection = MysqlDAOFactory.obtenerConexion(Variables.MYSQL_NUEVO_BD_NAME);
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
			String sql
				= "select "
				+ "codigo_fondo_pension codigoFondoPension, "
				+ "descripcion_corta descripcionCorta, "
				+ "descripcion_larga descripcionLarga, "
				+ "estado_registro estadoRegistro "
				+ "FROM fondo_pension "
				+ "where estado_registro = 1";
			ps = connection.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				FondoPensionBean fondoPension = new FondoPensionBean();
				fondoPension.setCodigoFondoPension(rs.getInt("codigoFondoPension"));
				fondoPension.setDescripcionCorta(rs.getString("descripcionCorta"));
				fondoPension.setDescripcionLarga(rs.getString("descripcionLarga").trim());
				JSONObject jsonObjFondoPension = new JSONObject(fondoPension);
				jsonArrayListarFondoPension.put(jsonObjFondoPension);
			}
			JSONObject jsonObjFondoPension = new JSONObject();
			jsonObjFondoPension.put("fondopension", jsonArrayListarFondoPension);

			response.setStatus(true);
			response.setMessage("Los fondos de pensiones se han listado correctamente");
			response.setData(jsonObjFondoPension);

		} catch (SQLException e) {
			e.printStackTrace();
			response.setStatus(false);
			response.setMessage("Error: " + e.getMessage() + " \n Error Code: [" + e.getErrorCode() + "]");
		} finally {
			try {
				if (rs != null) {
					rs.close();
				}
				if (ps != null) {
					ps.close();
				}
				if (connection != null) {
					connection.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

		jsonListarFondoPension = new JSONObject(response);
		return jsonListarFondoPension;
	}

	@Override
	public JSONObject validarExistenciaFondoPension(FondoPensionBean fondoPension) {
80
		System.out.println("FondoPensionMysqlDAO: validarExistenciaFondoPension");
81 82 83 84
		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
	}

}