Take a look at the JavaDocs for Statement#execute(String)
Returns:
true if the first result is a ResultSet object; false if it
is an update count or there are no results
You could use Statement#executeQuery(String) which will return a ResultSet, from which you will then need to inspect the result of the first row
Something like...
try (Statement stmt = con.createStatement()) {
try (ResultSet rs = stmt.executeQuery("select exists(select 1 from calcul where to_char(date, 'YYYY-MM')=to_char("+dates+", 'YYYY-MM') AND idproduit="+codeP+" AND ppa="+PPA+" AND tr="+TR+" AND net="+NET+" AND dateper='"+datePer+"')")) {
if (rs.next()) {
boolean exists = rs.getBoolean(1);
}
}
} catch (SQLException exp) {
exp.printStackTrace();
}
for example.
Having said that, I'd strongly encourage you to use a PreparedStatement, see Using Prepared Statements for more details
For example...
try (PreparedStatement stmt = con.prepareStatement("select exists(select 1 from calcul where to_char(date, 'YYYY-MM')=to_char(?, 'YYYY-MM') AND idproduit=? AND ppa=? AND tr=? AND net=? AND dateper='?')")) {
stmt.setString(1, dates);
stmt.setString(2, codeP);
stmt.setString(3, PPA);
stmt.setString(4, TR);
stmt.setString(5, NET);
stmt.setString(6, datePer);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
boolean exists = rs.getBoolean(1);
}
}
} catch (SQLException exp) {
exp.printStackTrace();
}
=sign is the assignment sign, while==is a comparison sign.PreparedStatement, do not concatenate SQL queries like that. You also need to useexecuteQuery()as clearly documented in the JavaDocs