ConfiguracionFichaSqlserverDAO.java 1.55 KB
Newer Older
Luis Gangas committed
1 2 3 4 5 6 7 8 9 10 11 12 13
package trismegistoplanilla.sqlserverdao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.json.JSONObject;
import trismegistoplanilla.dao.ConfiguracionFichaDAO;
import trismegistoplanilla.utilities.ResponseHelper;
import trismegistoplanilla.utilities.Variables;

public class ConfiguracionFichaSqlserverDAO implements ConfiguracionFichaDAO {

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 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
	@Override
	public JSONObject getDefaultMail() {
		System.out.println("ConfiguracionFichaSqlserverDAO: getDefaultMail");
		JSONObject JOmail = null;
		ResponseHelper response = new ResponseHelper();
		String sql = ""
			+ "select "
			+ "correo "
			+ "from configuracion_ficha "
			+ "where estado = 1";
		Connection conexion = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			conexion = SqlserverDAOFactory.obtenerConexion(Variables.BD_NAME);
			ps = conexion.prepareStatement(sql);
			rs = ps.executeQuery();
			rs.next();
			JSONObject obj = new JSONObject();
			obj.put("mail", rs.getString("correo"));
			response.setData(obj);
			response.setStatus(true);
		} 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 (conexion != null) {
					conexion.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		JOmail = new JSONObject(response);
		return JOmail;
	}
Luis Gangas committed
58 59

}