0
Good afternoon I have a table in the database with a date field, I need to add the values of the difference field between a specific date, for example: the last 10 minutes, the last 60 minutes, the last 7 days, but I’m not able to help me, follow the search code
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:sss");
String currentDateandTime = sdf.format(new Date());
public String nomeTabela() {
String Pesquisa = "";
ConexaoDao conexao = new ConexaoDao();
ObjetoConexao objConexao = new ObjetoConexao();
objConexao.db_connect_string = "flexvale.hopto.org:1433";
objConexao.db_name = "FlexPortaCom";
objConexao.db_userid = "sa";
objConexao.db_password = "flextelecom";
Connection conn = conexao.dbConnect(objConexao);
if (conn == null) {
Pesquisa = "Não foi possivel se conectar ao banco de dados";
} else
if (conn != null) try {
Statement statement = conn.createStatement();
String queryString = "select SUM(DIFERENÇA) as somaMes from TOTALIZADOR WHERE NID = 252 AND DATAHORA >=' "+ currentDateandTime + " -30 ' AND DATAHORA <= '"+ currentDateandTime +" '";
ResultSet rs;
rs = statement.executeQuery(queryString);
if (rs.next()) {
Pesquisa = rs.getString("somaMes");
}
} catch (SQLException e) {
Pesquisa = e.getMessage();
}
return Pesquisa ;