Help with sql server and android dats

Asked

Viewed 29 times

0

I have this code to do a search to SQL Server database but give me error:

Incorrect syntax next to '19'

Here’s the search code:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
String currentDateandTime = sdf.format(new Date () );
System.out.println(currentDateandTime);


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+" and DATAHORA = "+currentDateandTime+" ";
ResultSet rs;
  • It won’t be C with cedilla in DIFFERENCE?

  • Considerando que sua variavel currentDateandTime esteja com o conteúdo correto, escreva seu select assim:&#xA;" Select SUM(DIFERENÇA)as somaMes from TOTALIZADOR WHERE NID = 252 and DATAHORA >= '" + currentDateandTime + "' and DATAHORA <= '" + currentDateandTime + "'";

  • @Ronaldosantos: Date/time value has not been delimited between apostrophes, as suggested by Reginaldo. // But it makes sense to compare DATAHORA >= X and DATAHORA <= X ?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.