My query is to know how I can pass a ResultSet from SQLServer to JSON, since I am working with JavaScript libraries (ChartJS) to generate graphics for a dashboard and it only reads data in that format.
package DAO;
import conexion.Conexion;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.json.JSONObject;
public class GraficaDAO {
private static final Conexion con = Conexion.conectar();
private static PreparedStatement ps = null;
private static ResultSet res = null;
public ResultSet reporteMensual(String mes) throws Exception {
String sproc = "{call sp_EquiposMes (?)}";
try {
ps = con.getCnn().prepareCall(sproc);
ps.setString(1, mes.toString());
res = ps.executeQuery();
while (res.next()){
String equipos = res.getString(1);
}
} catch (SQLException ex) {
} finally {
try {
if (res != null) {
res.close();
}
if (ps != null) {
ps.close();
}
con.cerrarConexion();
} catch (Exception e) {
}
}
return res;
}
}
That is the code of my query, for the moment I was storing it in a String to corroborate if the data arrives.