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?
– ramaral
Considerando que sua variavel currentDateandTime esteja com o conteúdo correto, escreva seu select assim:
" Select SUM(DIFERENÇA)as somaMes from TOTALIZADOR WHERE NID = 252 and DATAHORA >= '" + currentDateandTime + "' and DATAHORA <= '" + currentDateandTime + "'";
– Reginaldo Rigo
@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 ?
– José Diz